import java.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;
public class Main {
    void solve() {
        int n=ni();
        g=new ArrayList[n+1];
        for(int i=1;i<=n;i++) g[i]=new ArrayList<>();
        for(int i=1;i<n;i++){
            int u=ni(),v=ni();
            g[u].add(v); g[v].add(u);
        }
        dp=new long[n+1][2][2];
        dfs(1,-1);
        pw.println(dp[1][1][1]);

    }
    ArrayList<Integer> g[];
    long dp[][][];
    void dfs(int v,int pr){
        int child=0;
        for(int u : g[v]){
            if(u!=pr) {
                dfs(u,v);
                child++;
            }
        }
        if(child==0){
            dp[v][0][0]=dp[v][1][1]=1;
            return;
        }
        long sm=1,sm2=1;
        for(int u : g[v]){
            if(u!=pr) {
                sm = mul(sm, add(dp[u][0][1], dp[u][1][1]));
                sm2=mul(sm2,dp[u][1][1]);
            }
        }
        dp[v][0][0]=sm;
        for(int u : g[v]){
            if(u!=pr){
                dp[v][0][1]=add(dp[v][0][1],mul(dp[u][0][0],mul(sm,modInverse(dp[u][0][1]+dp[u][1][1],M))));
                dp[v][1][1]=add(dp[v][1][1],mul(dp[u][0][0],mul(sm,modInverse(dp[u][0][1]+dp[u][1][1],M))));

            }
        }
        dp[v][1][1]=add(dp[v][1][1],sm2);

    }
    long sub(long a,long b){
        if(a>=M)a%=M;  if(b>=M)b%=M;
        a-=b;
        if(a<0) a+=M;
        return a;
    }
    long mul(long a,long b){
        a*=b;
        if(a>=M) a%=M;
        return a;
    }
    long add(long a,long b){
        if(a>=M)a%=M;  if(b>=M)b%=M;
        a+=b;
        if(a>=M) a-=M;
        return a;
    }
    long modpow(long a, long b,long M)
    {
        long r=1;
        while(b>0)
        {
            if((b&1)>0) r=mul(r,a);
            a=mul(a,a);
            b>>=1;
        }
        return r;
    }

    long modInverse(long A, long M)
    {

        return modpow(A,M-2,M);
    }

    long M = 998244353;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";

    void run() throws Exception {
        is = is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);

        Thread t = new Thread(null, null, "~", Runtime.getRuntime().maxMemory()){
            @Override
            public void run() {
                long s = System.currentTimeMillis();
                solve();

                pw.flush();
                if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
            }
        };
        t.start();
        t.join();
    }

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void tr(Object... o) {
        if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));
    }

}


import java.io.*;
import java.util.*;

public class I {

    public static boolean DEBUG = true;
    public static String name = "I";

    public static void main(String[] args) throws IOException {
    	FastScanner scan;
    	PrintWriter out;
    	if (DEBUG) {
    		scan = new FastScanner(System.in);
        	out = new PrintWriter(System.out);
    	}
    	else {
        	scan = new FastScanner(name + ".in");
        	out = new PrintWriter(new BufferedWriter(new FileWriter(name + ".out")));
    	}

		float N = Float.parseFloat(scan.nextString());
		float P = Float.parseFloat(scan.nextString());

        for(int i=0; i<=N; i+=1) {

            double val = i*(i-1)*(i-2)/6 + i*(i-1)*(N-i)/2 + i*(N-i)*(N-i-1)/4;
            val = val / (N*(N-1)*(N-2)/6);

            if(val >= P) {
                out.println((int)i);
                break;
            }
        }

        out.close();
    }

    static class BIT {
        public int[] tree;

        public BIT(int len) {
          tree = new int[len+5];
        }

        // updates tree by adding val to index
        public void update(int index, int val) {
          index++;
          while(index < tree.length) {
            tree[index] ^= val;
            index += index & -index;
          }
        }

        public int query(int index) {
          int result = 0;
          index++;
          while(index > 0) {
            result ^= tree[index];
            index -= index & -index;
          }

          return result;
        }

        public int rangeSum(int low, int high) {
          return query(high) - query(low-1);
        }

      }

    /* BINARY LIFTING - Preprocess O(NlogN) - Query O(logN)*/
    static ArrayList<Integer>[] adjList;
    static int[] tin, tout;
    static int[][] BL;
    static int ct;

    public static void preprocess(int root) {
        ct = 0;
        tin = new int[adjList.length];
        tout = new int[adjList.length];
        BL = new int[adjList.length][log2(adjList.length)+1];

        recur_bl(root,root);
    }

    public static void recur_bl(int v, int p) {
        tin[v] = ++ct;
        BL[v][0] = p;
        for (int i=1; i <= log2(adjList.length); ++i) BL[v][i] = BL[BL[v][i-1]][i-1];

        for (int i=0; i<adjList[v].size(); i++) if(adjList[v].get(i) != p) recur_bl(adjList[v].get(i), v);

        tout[v] = ++ct;
    }

    public static boolean is_ancestor(int u, int v) {
        return tin[u] <= tin[v] && tout[u] >= tout[v];
    }

    public static int lca(int u, int v) {
        if(is_ancestor(u, v)) return u;
        if(is_ancestor(v, u)) return v;

        for(int i=log2(adjList.length); i >= 0; --i) if(!is_ancestor(BL[u][i], v)) u = BL[u][i];

        return BL[u][0];
    }

    public static int log2(int n) {
        return (int)Math.ceil(Math.log10(n)/Math.log10(2));
    }

    static class FastScanner {

		// Is your Fast I/O being bad?

		InputStream dis;
		byte[] buffer = new byte[1 << 17];
		int pointer = 0;

		public FastScanner (String fileName) throws IOException {
			dis = new FileInputStream(fileName);
		}

		public FastScanner (InputStream is) throws IOException {
			dis = is;
		}

		int nextInt() throws IOException {
			int ret = 0;

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}

			return (negative) ? -ret : ret;
		}

		long nextLong() throws IOException {
			long ret = 0;

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}

			return (negative) ? -ret : ret;
		}

		byte nextByte() throws IOException {
			if (pointer == buffer.length) {
				dis.read(buffer, 0, buffer.length);
				pointer = 0;
			}
			return buffer[pointer++];
		}

		String nextString() throws IOException {
			StringBuffer ret = new StringBuffer();

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			while (b > ' ') {
				ret.appendCodePoint(b);
				b = nextByte();
			}

			return ret.toString();
		}

	}
}


import java.io.BufferedReader;
        import java.io.IOException;
        import java.io.InputStreamReader;
        import java.util.StringTokenizer;

public class bubblestrike {
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(f.readLine());
        int x = Integer.parseInt(st.nextToken());
        double prob = Double.parseDouble(st.nextToken());
        int pos = x;
        for (int a=x; a>0; a/=2){
            while (pos-a>=0&&check(pos-a,x-(pos-a),prob)){
                pos-=a;
            }
        }
        System.out.println(pos);

    }
    public static boolean check (int good, int bad, double proba){
        double g=good+0.0;
        double b=bad+0.0;
        double ans = (0.25*b*Math.max(0,b-1.0)*g+(g*(Math.max(0,g-1)*Math.max(0,g-2)/6.0)+b*0.5*(g)*Math.max(0,g-1)))/((g+b)*Math.max(0,g+b-1)*Math.max(0,g+b-2)/6.0);
        return ans >=proba;
    }
}


import java.util.*;
import java.io.*;

public class _1599_C {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer line = new StringTokenizer(in.readLine());
        int n = Integer.parseInt(line.nextToken());
        double p = Double.parseDouble(line.nextToken());
        int total = choose_three(n);
        for(int i = 0; i <= n; i++) {
            double prob = 0;
            double p1 = (double)i * choose_two(n - i) / total;
            double p2 = (double)choose_two(i) * (n - i) / total;
            double p3 = (double)choose_three(i) / total;
            prob = p1 / 2 + p2 + p3;
            if(prob >= p) {
                out.println(i);
                break;
            }
        }
        in.close();
        out.close();
    }
    static int choose_two(int n) {
        if(n < 2) return 0;
        return n * (n - 1) / 2;
    }
    static int choose_three(int n) {
        if(n < 3) return 0;
        return n * (n - 1) * (n - 2) / 6;
    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class B {
    static BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter pw = new PrintWriter(System.out);
    public static double func(double x, double n){

        return -n*(n*n-3*n-3*x*x+9*x-4)/(2*(x-2)*(x-1)*x);
    }
    public static void main(String[] args) throws IOException {
        StringTokenizer st = new StringTokenizer(r.readLine());
        ArrayList<Integer> nums = new ArrayList<>();
        int x = Integer.parseInt(st.nextToken());
        double p = Double.parseDouble(st.nextToken());
        int ans = 0;
        for(int i = 0; i<=x; i++){
            if(func(x,i)  >= p){
                ans = i;
                break;
            }
        }
        pw.print(ans);
        pw.close(); // make sure to include this line -- closes io and flushes the output
    }
}


import java.io.*;
import java.util.*;

public final class Main {

    static PrintWriter out = new PrintWriter(System.out);
    static FastReader in = new FastReader();
    static Pair[] moves = new Pair[]{new Pair(-1, 0), new Pair(0, 1), new Pair(1, 0), new Pair(0, -1)};
    static int mod = (int) (1e9 + 7);
    static int mod2 = 998244353;

    public static void main(String[] args) {
        int tt = 1;
        while (tt-- > 0) {
            solve();
        }
        out.flush();
    }

    public static void solve() {
        int n = i();
        double p = d();

        int l = 0;
        int r = n - 1;
        while (l < r) {
            int m = (l + r) / 2;
            double x = cal(m, n);
            if (x >= p) {
                r = m;
            } else {
                l = m + 1;
            }
        }
        out.println(l);
    }

    private static double cal(int m, int n) {
        long ttl = comb(n, 3);
        double ans = 0d;
        ans += 1d * (comb(m, 3));
        ans += 1d * (comb(m, 2) * comb(n - m, 1));
        ans += 0.5 * (comb(m, 1) * comb(n - m, 2));
        return ans / ttl;
    }

    private static long comb(int n, int c) {
        if (c > n) {
            return 0;
        }
        if (c == n) {
            return 1;
        }
        long ans = 1L;
        for (int i = 0; i < c; i++) {
            ans *= (n - i);
        }
        for (int i = 1; i <= c; i++) {
            ans /= i;
        }
        return ans;
    }

    static long[] pre(int[] a) {
        long[] pre = new long[a.length + 1];
        pre[0] = 0;
        for (int i = 0; i < a.length; i++) {
            pre[i + 1] = pre[i] + a[i];
        }
        return pre;
    }

    static void print(char A[]) {
        for (char c : A) {
            out.print(c);
        }
        out.println();
    }

    static void print(boolean A[]) {
        for (boolean c : A) {
            out.print(c + " ");
        }
        out.println();
    }

    static void print(int A[]) {
        for (int c : A) {
            out.print(c + " ");
        }
        out.println();
    }

    static void print(long A[]) {
        for (long i : A) {
            out.print(i + " ");
        }
        out.println();
    }

    static void print(List<Integer> A) {
        for (int a : A) {
            out.print(a + " ");
        }
    }

    static int i() {
        return in.nextInt();
    }

    static long l() {
        return in.nextLong();
    }

    static double d() {
        return in.nextDouble();
    }

    static String s() {
        return in.nextLine();
    }

    static int[][] inputWithIdx(int N) {
        int A[][] = new int[N][2];
        for (int i = 0; i < N; i++) {
            A[i] = new int[]{i, in.nextInt()};
        }
        return A;
    }

    static int[] input(int N) {
        int A[] = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextInt();
        }
        return A;
    }

    static long[] inputLong(int N) {
        long A[] = new long[N];
        for (int i = 0; i < A.length; i++) {
            A[i] = in.nextLong();
        }
        return A;
    }

    static int GCD(int a, int b) {
        if (b == 0) {
            return a;
        } else {
            return GCD(b, a % b);
        }
    }

    static long GCD(long a, long b) {
        if (b == 0) {
            return a;
        } else {
            return GCD(b, a % b);
        }
    }

    static long LCM(int a, int b) {
        return (long) a / GCD(a, b) * b;
    }

    static long LCM(long a, long b) {
        return a / GCD(a, b) * b;
    }

    static void shuffleAndSort(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            int rand = (int) (Math.random() * arr.length);
            int temp = arr[rand];
            arr[rand] = arr[i];
            arr[i] = temp;
        }
        Arrays.sort(arr);
    }

    static void shuffleAndSort(int[][] arr, Comparator<? super int[]> comparator) {
        for (int i = 0; i < arr.length; i++) {
            int rand = (int) (Math.random() * arr.length);
            int[] temp = arr[rand];
            arr[rand] = arr[i];
            arr[i] = temp;
        }
        Arrays.sort(arr, comparator);
    }

    static void shuffleAndSort(long[] arr) {
        for (int i = 0; i < arr.length; i++) {
            int rand = (int) (Math.random() * arr.length);
            long temp = arr[rand];
            arr[rand] = arr[i];
            arr[i] = temp;
        }
        Arrays.sort(arr);
    }

    static boolean isPerfectSquare(double number) {
        double sqrt = Math.sqrt(number);
        return ((sqrt - Math.floor(sqrt)) == 0);
    }

    static void swap(int A[], int a, int b) {
        int t = A[a];
        A[a] = A[b];
        A[b] = t;
    }

    static long pow(long a, long b, int mod) {
        long pow = 1;
        long x = a;
        while (b != 0) {
            if ((b & 1) != 0) {
                pow = (pow * x) % mod;
            }
            x = (x * x) % mod;
            b /= 2;
        }
        return pow;
    }

    static long pow(long a, long b) {
        long pow = 1;
        long x = a;
        while (b != 0) {
            if ((b & 1) != 0) {
                pow *= x;
            }
            x = x * x;
            b /= 2;
        }
        return pow;
    }

    static long modInverse(long x, int mod) {
        return pow(x, mod - 2, mod);
    }

    static boolean isPrime(long N) {
        if (N <= 1) {
            return false;
        }
        if (N <= 3) {
            return true;
        }
        if (N % 2 == 0 || N % 3 == 0) {
            return false;
        }
        for (int i = 5; i * i <= N; i = i + 6) {
            if (N % i == 0 || N % (i + 2) == 0) {
                return false;
            }
        }
        return true;
    }

    public static String reverse(String str) {
        if (str == null) {
            return null;
        }
        return new StringBuilder(str).reverse().toString();
    }

    public static String repeat(char ch, int repeat) {
        if (repeat <= 0) {
            return "";
        }
        final char[] buf = new char[repeat];
        for (int i = repeat - 1; i >= 0; i--) {
            buf[i] = ch;
        }
        return new String(buf);
    }

    public static int[] manacher(String s) {
        char[] chars = s.toCharArray();
        int n = s.length();
        int[] d1 = new int[n];
        for (int i = 0, l = 0, r = -1; i < n; i++) {
            int k = (i > r) ? 1 : Math.min(d1[l + r - i], r - i + 1);
            while (0 <= i - k && i + k < n && chars[i - k] == chars[i + k]) {
                k++;
            }
            d1[i] = k--;
            if (i + k > r) {
                l = i - k;
                r = i + k;
            }
        }
        return d1;
    }

    public static int[] kmp(String s) {
        int n = s.length();
        int[] res = new int[n];
        for (int i = 1; i < n; ++i) {
            int j = res[i - 1];
            while (j > 0 && s.charAt(i) != s.charAt(j)) {
                j = res[j - 1];
            }
            if (s.charAt(i) == s.charAt(j)) {
                ++j;
            }
            res[i] = j;
        }
        return res;
    }
}

class Pair {

    int i, j;

    Pair(int i, int j) {
        this.i = i;
        this.j = j;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Pair pair = (Pair) o;
        return i == pair.i && j == pair.j;
    }

    @Override
    public int hashCode() {
        return Objects.hash(i, j);
    }
}

class FastReader {

    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

class Node {

    int data, open, close;

    Node() {
        this(0, 0, 0);
    }

    Node(int data, int open, int close) {
        this.data = data;
        this.open = open;
        this.close = close;
    }
}

class ST {

    int n;
    Node[] st;

    ST(int n) {
        this.n = n;
        st = new Node[4 * Integer.highestOneBit(n)];
    }

    void build(Node[] nodes) {
        build(0, 0, n - 1, nodes);
    }

    private void build(int id, int l, int r, Node[] nodes) {
        if (l == r) {
            st[id] = nodes[l];
            return;
        }
        int mid = (l + r) >> 1;
        build((id << 1) + 1, l, mid, nodes);
        build((id << 1) + 2, mid + 1, r, nodes);
        st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]);
    }

    void update(int i, Node node) {
        update(0, 0, n - 1, i, node);
    }

    private void update(int id, int l, int r, int i, Node node) {
        if (i < l || r < i) {
            return;
        }
        if (l == r) {
            st[id] = node;
            return;
        }
        int mid = (l + r) >> 1;
        update((id << 1) + 1, l, mid, i, node);
        update((id << 1) + 2, mid + 1, r, i, node);
        st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]);
    }

    Node get(int x, int y) {
        return get(0, 0, n - 1, x, y);
    }

    private Node get(int id, int l, int r, int x, int y) {
        if (x > r || y < l) {
            return new Node();
        }
        if (x <= l && r <= y) {
            return st[id];
        }
        int mid = (l + r) >> 1;
        return comb(get((id << 1) + 1, l, mid, x, y), get((id << 1) + 2, mid + 1, r, x, y));
    }

    Node comb(Node a, Node b) {
        if (a == null) {
            return b;
        }
        if (b == null) {
            return a;
        }
        int min = Math.min(a.open, b.close);
        return new Node(a.data + b.data + min * 2, a.open + b.open - min, a.close + b.close - min);
    }
}


import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;
public class C {
    public static void main(String[] args) throws Exception {
        new C().run();
    }
    public void run() throws Exception {
        FastScanner f = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = f.nextInt();
        double d = f.nextDouble();
        for(int i = 0; i <= n; i++) {
            double prob = 1.5 * i * (n-i) * (n-i-1) / n / (n-1) / (n-2);
            prob += 3.0 * i * (i-1) * (n-i) / n / (n-1) / (n-2);
            prob += 1.0 * i * (i-1) * (i-2) / n / (n-1) / (n-2);
            if(prob + 1e-8 >= d) {
                out.println(i);
                break;
            }
        }
///
        out.flush();
	}
///
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}
		public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch(IOException e) {
				throw new RuntimeException(e);
			}
		}
	}
}


import java.util.Scanner;

public class I {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        solve(s.nextInt(), (int)(Double.parseDouble(s.next()) * 10000));
    }

    public static void solve(long n, long p) {
        long studied = 0;
        long notStudied = n;

        long zero;
        long one;
        long two;
        long three;

        long thisP;

        while (true) {
            zero = notStudied * (notStudied - 1) * (notStudied - 2) / 6;
            one = studied * notStudied * (notStudied - 1) / 2;
            two = studied * (studied - 1) * notStudied / 2;
            three = studied * (studied - 1) * (studied - 2) / 6;

            thisP = zero * 0 + one * 1 + two * 2 + three * 2;
            if (thisP * 5000 >= p * n * (n - 1) * (n - 2) / 6) {
                System.out.println(studied);
                return;
            }

            studied++;
            notStudied--;
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author lewin
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader2 in = new InputReader2(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        CBubbleStrike solver = new CBubbleStrike();
        solver.solve(1, in, out);
        out.close();
    }

    static class CBubbleStrike {
        double getProb(int x, int n) {
            return 3.0 / 2.0 * x / n * (n - x) / (n - 1) * (n - x - 1) / (n - 2) + 3.0 * x / n * (x - 1) / (n - 1) * (n - x) / (n - 2) + 1.0 * x / n * (x - 1) / (n - 1) * (x - 2) / (n - 2);
        }

        public void solve(int testNumber, InputReader2 in, OutputWriter out) {
            int n = in.nextInt();
            double p = in.nextDouble();
            int x = 0;
            while (getProb(x, n) < p) x++;
            out.println(x);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }

    static class InputReader2 {
        private BufferedReader in;
        private StringTokenizer st;

        public InputReader2(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

    }
}


import java.awt.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

import static java.lang.Math.max;
import static java.lang.Math.min;

public class B implements Runnable{

    private final static Random rnd = new Random();

    // SOLUTION!!!
    // HACK ME PLEASE IF YOU CAN!!!
    // PLEASE!!!
    // PLEASE!!!
    // PLEASE!!!

    final int MAX_SIZE = 2000 * 1000;

    void solve() {
        int n = readInt();

        int c0 = readInt();
        int c1 = readInt();

        if (c0 > c1) {
            int tmp = c0;
            c0 = c1;
            c1 = tmp;
        }

        long answer = getAnswer(n, c0, c1);
        out.println(answer);
    }

    long getAnswer(int n, long c0, long c1) {
        long c01 = c0 + c1;

        if (n == 2) {
            return c01;
        }

        long answer = c1;
        n -= 2;

        long x = (c0 == 0 ? Integer.MAX_VALUE : c1 / c0);
        x = Math.min(x, n);

        answer += x * c1 + (x + 1) * (x + 2) / 2 * c0;
        n -= x;

        NavigableMap<Long, Integer> costs = new TreeMap<>();

//        costs.put(c1, 1);
        for (int count = 0; count <= Math.min(MAX_SIZE, x); ++count) {
            inc(costs, count * c0 + c1, 1);
        }
        inc(costs, (x + 1) * c0, 1);

        while (n > 0) {
            Map.Entry<Long, Integer> minCostEntry = costs.pollFirstEntry();

            long cost = minCostEntry.getKey();
            int count = minCostEntry.getValue();
            count = Math.min(count, n);

            n -= count;
            answer += (cost + c01) * count;

            inc(costs, cost + c0, count);
            inc(costs, cost + c1, count);
        }

        return answer;
    }

    void inc(NavigableMap<Long, Integer> counts, long cost, int count) {
        Integer curCount = counts.get(cost);
        if (curCount == null) {
            curCount = 0;
        }

        counts.put(cost, curCount + count);

        while (counts.size() > MAX_SIZE) {
            counts.pollLastEntry();
        }
    }

    /////////////////////////////////////////////////////////////////////

    private final static boolean FIRST_INPUT_STRING = false;
    private final static boolean MULTIPLE_TESTS = true;
    private final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    private final static int MAX_STACK_SIZE = 128;

    private final static boolean OPTIMIZE_READ_NUMBERS = false;

    /////////////////////////////////////////////////////////////////////

    public void run(){
        try{
            timeInit();
            Locale.setDefault(Locale.US);

            init();

            if (ONLINE_JUDGE) {
                solve();
            } else {
                do {
                    try {
                        timeInit();
                        solve();
                        time();

                        out.println();
                    } catch (NumberFormatException e) {
                        break;
                    } catch (NullPointerException e) {
                        if (FIRST_INPUT_STRING) break;
                        else throw e;
                    }
                } while (MULTIPLE_TESTS);
            }

            out.close();
            time();
        }catch (Exception e){
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    /////////////////////////////////////////////////////////////////////

    private BufferedReader in;
    private OutputWriter out;
    private StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args){
        new Thread(null, new B(), "", MAX_STACK_SIZE * (1L << 20)).start();
    }

    /////////////////////////////////////////////////////////////////////

    private void init() throws FileNotFoundException{
        Locale.setDefault(Locale.US);

        if (ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new OutputWriter(System.out);
        }else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new OutputWriter("output.txt");
        }
    }

    ////////////////////////////////////////////////////////////////

    private long timeBegin;

    private void timeInit() {
        this.timeBegin = System.currentTimeMillis();
    }

    private void time(){
        long timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    private void debug(Object... objects){
        if (ONLINE_JUDGE){
            for (Object o: objects){
                System.err.println(o.toString());
            }
        }
    }

    /////////////////////////////////////////////////////////////////////

    private String delim = " ";

    private String readLine() {
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeIOException(e);
        }
    }

    private String readString() {
        try {
            while(!tok.hasMoreTokens()){
                tok = new StringTokenizer(readLine());
            }

            return tok.nextToken(delim);
        } catch (NullPointerException e) {
            return null;
        }
    }

    /////////////////////////////////////////////////////////////////

    private final char NOT_A_SYMBOL = '\0';

    private char readChar() {
        try {
            int intValue = in.read();

            if (intValue == -1){
                return NOT_A_SYMBOL;
            }

            return (char) intValue;
        } catch (IOException e) {
            throw new RuntimeIOException(e);
        }
    }

    private char[] readCharArray() {
        return readLine().toCharArray();
    }

    private char[][] readCharField(int rowsCount) {
        char[][] field = new char[rowsCount][];
        for (int row = 0; row < rowsCount; ++row) {
            field[row] = readCharArray();
        }

        return field;
    }

    /////////////////////////////////////////////////////////////////

    private long optimizedReadLong() {
        long result = 0;
        boolean started = false;
        while (true) {
            try {
                int j = in.read();
                if (-1 == j) {
                    if (started) return result;
                    throw new NumberFormatException();
                }

                if ('0' <= j && j <= '9') {
                    result = result * 10 + j - '0';
                    started = true;
                } else if (started) {
                    return result;
                }
            } catch (IOException e) {
                throw new RuntimeIOException(e);
            }
        }
    }

    private int readInt() {

        if (!OPTIMIZE_READ_NUMBERS) {
            return Integer.parseInt(readString());
        } else {
            return (int) optimizedReadLong();
        }
    }

    private int[] readIntArray(int size) {
        int[] array = new int[size];

        for (int index = 0; index < size; ++index){
            array[index] = readInt();
        }

        return array;
    }

    private int[] readSortedIntArray(int size) {
        Integer[] array = new Integer[size];

        for (int index = 0; index < size; ++index) {
            array[index] = readInt();
        }
        Arrays.sort(array);

        int[] sortedArray = new int[size];
        for (int index = 0; index < size; ++index) {
            sortedArray[index] = array[index];
        }

        return sortedArray;
    }

    private int[] readIntArrayWithDecrease(int size) {
        int[] array = readIntArray(size);

        for (int i = 0; i < size; ++i) {
            array[i]--;
        }

        return array;
    }

    ///////////////////////////////////////////////////////////////////

    private int[][] readIntMatrix(int rowsCount, int columnsCount) {
        int[][] matrix = new int[rowsCount][];

        for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {
            matrix[rowIndex] = readIntArray(columnsCount);
        }

        return matrix;
    }

    private int[][] readIntMatrixWithDecrease(int rowsCount, int columnsCount) {
        int[][] matrix = new int[rowsCount][];

        for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {
            matrix[rowIndex] = readIntArrayWithDecrease(columnsCount);
        }

        return matrix;
    }

    ///////////////////////////////////////////////////////////////////

    private long readLong() {
        if (!OPTIMIZE_READ_NUMBERS) {
            return Long.parseLong(readString());
        } else {
            return optimizedReadLong();
        }
    }

    private long[] readLongArray(int size) {
        long[] array = new long[size];

        for (int index = 0; index < size; ++index){
            array[index] = readLong();
        }

        return array;
    }

    ////////////////////////////////////////////////////////////////////

    private double readDouble() {
        return Double.parseDouble(readString());
    }

    private double[] readDoubleArray(int size) {
        double[] array = new double[size];

        for (int index = 0; index < size; ++index){
            array[index] = readDouble();
        }

        return array;
    }

    ////////////////////////////////////////////////////////////////////

    private BigInteger readBigInteger() {
        return new BigInteger(readString());
    }

    private BigDecimal readBigDecimal() {
        return new BigDecimal(readString());
    }

    /////////////////////////////////////////////////////////////////////

    private Point readPoint() {
        int x = readInt();
        int y = readInt();
        return new Point(x, y);
    }

    private Point[] readPointArray(int size) {
        Point[] array = new Point[size];

        for (int index = 0; index < size; ++index){
            array[index] = readPoint();
        }

        return array;
    }

    /////////////////////////////////////////////////////////////////////

    private List<Integer>[] readGraph(int vertexNumber, int edgeNumber) {
        @SuppressWarnings("unchecked")
        List<Integer>[] graph = new List[vertexNumber];

        for (int index = 0; index < vertexNumber; ++index){
            graph[index] = new ArrayList<Integer>();
        }

        while (edgeNumber-- > 0){
            int from = readInt() - 1;
            int to = readInt() - 1;

            graph[from].add(to);
            graph[to].add(from);
        }

        return graph;
    }

    /////////////////////////////////////////////////////////////////////

    private static class IntIndexPair {

        static Comparator<IntIndexPair> increaseComparator = new Comparator<B.IntIndexPair>() {

            @Override
            public int compare(B.IntIndexPair indexPair1, B.IntIndexPair indexPair2) {
                int value1 = indexPair1.value;
                int value2 = indexPair2.value;

                if (value1 != value2) return value1 - value2;

                int index1 = indexPair1.index;
                int index2 = indexPair2.index;

                return index1 - index2;
            }
        };

        static Comparator<IntIndexPair> decreaseComparator = new Comparator<B.IntIndexPair>() {

            @Override
            public int compare(B.IntIndexPair indexPair1, B.IntIndexPair indexPair2) {
                int value1 = indexPair1.value;
                int value2 = indexPair2.value;

                if (value1 != value2) return -(value1 - value2);

                int index1 = indexPair1.index;
                int index2 = indexPair2.index;

                return index1 - index2;
            }
        };

        int value, index;

        IntIndexPair(int value, int index) {
            super();
            this.value = value;
            this.index = index;
        }

        int getRealIndex() {
            return index + 1;
        }
    }

    private IntIndexPair[] readIntIndexArray(int size) {
        IntIndexPair[] array = new IntIndexPair[size];

        for (int index = 0; index < size; ++index) {
            array[index] = new IntIndexPair(readInt(), index);
        }

        return array;
    }

    /////////////////////////////////////////////////////////////////////

    private static class OutputWriter extends PrintWriter {

        final int DEFAULT_PRECISION = 12;

        private int precision;
        private String format, formatWithSpace;

        {
            precision = DEFAULT_PRECISION;

            format = createFormat(precision);
            formatWithSpace = format + " ";
        }

        OutputWriter(OutputStream out) {
            super(out);
        }

        OutputWriter(String fileName) throws FileNotFoundException {
            super(fileName);
        }

        int getPrecision() {
            return precision;
        }

        void setPrecision(int precision) {
            precision = max(0, precision);
            this.precision = precision;

            format = createFormat(precision);
            formatWithSpace = format + " ";
        }

        String createFormat(int precision){
            return "%." + precision + "f";
        }

        @Override
        public void print(double d){
            printf(format, d);
        }

        void printWithSpace(double d){
            printf(formatWithSpace, d);
        }

        void printAll(double...d){
            for (int i = 0; i < d.length - 1; ++i){
                printWithSpace(d[i]);
            }

            print(d[d.length - 1]);
        }

        @Override
        public void println(double d){
            printlnAll(d);
        }

        void printlnAll(double... d){
            printAll(d);
            println();
        }
    }

    /////////////////////////////////////////////////////////////////////

    private static class RuntimeIOException extends RuntimeException {

        /**
         *
         */
        private static final long serialVersionUID = -6463830523020118289L;

        RuntimeIOException(Throwable cause) {
            super(cause);
        }
    }

    /////////////////////////////////////////////////////////////////////
    //////////////// Some useful constants and functions ////////////////
    /////////////////////////////////////////////////////////////////////

    private static final int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    private static final int[][] steps8 = {
            {-1, 0}, {1, 0}, {0, -1}, {0, 1},
            {-1, -1}, {1, 1}, {1, -1}, {-1, 1}
    };

    private static boolean checkCell(int row, int rowsCount, int column, int columnsCount) {
        return checkIndex(row, rowsCount) && checkIndex(column, columnsCount);
    }

    private static boolean checkIndex(int index, int lim){
        return (0 <= index && index < lim);
    }

    /////////////////////////////////////////////////////////////////////

    private static boolean checkBit(int mask, int bit){
        return (mask & (1 << bit)) != 0;
    }
    private static boolean checkBit(long mask, int bit){
        return (mask & (1L << bit)) != 0;
    }

    /////////////////////////////////////////////////////////////////////

    private static long getSum(int[] array) {
        long sum = 0;
        for (int value: array) {
            sum += value;
        }

        return sum;
    }

    private static Point getMinMax(int[] array) {
        int min = array[0];
        int max = array[0];

        for (int index = 0, size = array.length; index < size; ++index, ++index) {
            int value = array[index];

            if (index == size - 1) {
                min = min(min, value);
                max = max(max, value);
            } else {
                int otherValue = array[index + 1];

                if (value <= otherValue) {
                    min = min(min, value);
                    max = max(max, otherValue);
                } else {
                    min = min(min, otherValue);
                    max = max(max, value);
                }
            }
        }

        return new Point(min, max);
    }

    /////////////////////////////////////////////////////////////////////

    private static int[] getPrimes(int n) {
        boolean[] used = new boolean[n];
        used[0] = used[1] = true;

        int size = 0;
        for (int i = 2; i < n; ++i) {
            if (!used[i]) {
                ++size;
                for (int j = 2 * i; j < n; j += i) {
                    used[j] = true;
                }
            }
        }

        int[] primes = new int[size];
        for (int i = 0, cur = 0; i < n; ++i) {
            if (!used[i]) {
                primes[cur++] = i;
            }
        }

        return primes;
    }

    /////////////////////////////////////////////////////////////////////

    private static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
    }

    private static long gcd(long a, long b) {
        return (a == 0 ? b : gcd(b % a, a));
    }

    /////////////////////////////////////////////////////////////////////

    private static class IdMap<KeyType> extends HashMap<KeyType, Integer> {

        /**
         *
         */
        private static final long serialVersionUID = -3793737771950984481L;

        public IdMap() {
            super();
        }

        int getId(KeyType key) {
            Integer id = super.get(key);
            if (id == null) {
                super.put(key, id = size());
            }

            return id;
        }
    }
}


import java.io.*;
import java.util.*;

public class G {

	static final int P = 1_000_000_007;

	void submit() {
		int n = nextInt();
		int m = nextInt();
		long exp = nextLong();
		int[] a = new int[n];
		int[] b = new int[m];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		int maxCoef = 0;
		for (int i = 0; i < m; i++) {
			b[i] = nextInt();
			maxCoef = Math.max(maxCoef, b[i]);
		}

		int[] bPoly = new int[maxCoef + 1];
		bPoly[maxCoef] = 1;
		for (int pow : b) {
			bPoly[maxCoef - pow]--;
			if (bPoly[maxCoef - pow] < 0) {
				bPoly[maxCoef - pow] += P;
			}
		}

		int[] aPoly = {};
		for (int pow : a) {
			aPoly = sum(aPoly, quotPow(new int[] { 0, 1 }, bPoly, pow));
		}
		int[] ans = quotPow(aPoly, bPoly, exp);

		ans = prod(ans, quotPow(new int[] { 0, 1 }, bPoly, maxCoef));
		ans = quot(ans, bPoly);

		out.println((long)ans[0] * inv(P - bPoly[0]) % P);
	}

	int inv(int x) {
		return x == 1 ? 1 : P - (int)((long)(P / x) * inv(P % x) % P);
	}

	int[] quotPow(int[] a, int[] b, long n) {
		a = quot(a, b);
		int[] ret = { 1 };
		for (; n > 0; n >>= 1) {
			if ((n & 1) == 1) {
				ret = quot(prod(ret, a), b);
			}
			a = quot(prod(a, a), b);
		}
		return ret;
	}

	int[] sum(int[] a, int[] b) {
		int[] c = Arrays.copyOf(a, Math.max(a.length, b.length));
		for (int i = 0; i < b.length; i++) {
			c[i] += b[i];
			if (c[i] >= P) {
				c[i] -= P;
			}
		}
		return c;
	}

	int[] prod(int[] a, int[] b) {
		int[] c = new int[a.length + b.length - 1];
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < b.length; j++) {
				c[i + j] += (int) ((long) a[i] * b[j] % P);
				if (c[i + j] >= P) {
					c[i + j] -= P;
				}
			}
		}
		return c;
	}

	int[] quot(int[] a, int[] b) {
		a = a.clone();
		// leading coef of b is 1
		if (a.length < b.length) {
			return a;
		}
		int degB = b.length - 1;
		for (int ptr = a.length - 1; ptr >= degB; ptr--) {
			long coef = a[ptr];
			for (int i = 0, j = ptr - degB; i < degB; i++, j++) {
				a[j] -= (int) (coef * b[i] % P);
				if (a[j] < 0) {
					a[j] += P;
				}
			}
		}
		return Arrays.copyOf(a, degB);
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	G() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new G();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


 import java.io.*;
import java.util.*;

public class MethodTest {

	static final int P = 1_000_000_007;

	static void submit() {
		int n = nextInt();
		int m = nextInt();
		long exp = nextLong();
		int[] a = new int[n];
		int[] b = new int[m];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		int maxCoef = 0;
		for (int i = 0; i < m; i++) {
			b[i] = nextInt();
			maxCoef = Math.max(maxCoef, b[i]);
		}

		int[] bPoly = new int[maxCoef + 1];
		bPoly[maxCoef] = 1;
		for (int pow : b) {
			bPoly[maxCoef - pow]--;
			if (bPoly[maxCoef - pow] < 0) {
				bPoly[maxCoef - pow] += P;
			}
		}

		int[] aPoly = {};
		for (int pow : a) {
			aPoly = sum(aPoly, quotPow(new int[] { 0, 1 }, bPoly, pow));
		}
		int[] ans = quotPow(aPoly, bPoly, exp);

		ans = prod(ans, quotPow(new int[] { 0, 1 }, bPoly, maxCoef));
		ans = quot(ans, bPoly);

		out.println((long)ans[0] * inv(P - bPoly[0]) % P);
	}

	static int inv(int x) {
		return x == 1 ? 1 : P - (int)((long)(P / x) * inv(P % x) % P);
	}

	static int[] quotPow(int[] a, int[] b, long n) {
		a = quot(a, b);
		int[] ret = { 1 };
		for (; n > 0; n >>= 1) {
			if ((n & 1) == 1) {
				ret = quot(prod(ret, a), b);
			}
			a = quot(prod(a, a), b);
		}
		return ret;
	}

	static int[] sum(int[] a, int[] b) {
		int[] c = Arrays.copyOf(a, Math.max(a.length, b.length));
		for (int i = 0; i < b.length; i++) {
			c[i] += b[i];
			if (c[i] >= P) {
				c[i] -= P;
			}
		}
		return c;
	}

	static int[] prod(int[] a, int[] b) {
		int[] c = new int[a.length + b.length - 1];
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < b.length; j++) {
				c[i + j] += (int) ((long) a[i] * b[j] % P);
				if (c[i + j] >= P) {
					c[i + j] -= P;
				}
			}
		}
		return c;
	}

	static int[] quot(int[] a, int[] b) {
		a = a.clone();
		// leading coef of b is 1
		if (a.length < b.length) {
			return a;
		}
		int degB = b.length - 1;
		for (int ptr = a.length - 1; ptr >= degB; ptr--) {
			long coef = a[ptr];
			for (int i = 0, j = ptr - degB; i < degB; i++, j++) {
				a[j] -= (int) (coef * b[i] % P);
				if (a[j] < 0) {
					a[j] += P;
				}
			}
		}
		return Arrays.copyOf(a, degB);
	}

	static void preCalc() {

	}

	static void stress() {

	}

	static void test() {

	}

	public static void run() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		run();
	}

	static BufferedReader br;
	static PrintWriter out;
	static StringTokenizer st;

	static String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	static String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	static int nextInt() {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


import java.io.*;
import java.math.*;
import java.security.KeyStore.Entry;
import java.util.*;

public class CODEFORCES {
	private InputStream is;
	private PrintWriter out;

	void solve() {
		int a = ni(), b = ni(), l = ni(), r = ni();
		String fin = new String();
		for (int i = 0; i < a; i++)
			fin = fin + (char) ('a' + i);
		for (int i = 0; i < b; i++)
			fin = fin + (char) ('a' + a - 1);
		int x = l % (a + b);
		if (x == 0)
			x = a + b;
		fin = fin.substring(x - 1);
		HashSet<Character> set = new HashSet<Character>();
		for (int i = fin.length() - 1; i >= 0 && i >= fin.length() - a; i--)
			set.add(fin.charAt(i));
		int op = a;
		for (int i = 0; i < 26 && op > 0; i++) {
			if (set.contains((char) ('a' + i)))
				continue;
			fin = fin + (char) ('a' + i);
			op--;
		}
		char ch = fin.charAt(fin.length() - 1);
		for (int i = 0; i < b; i++)
			fin = fin + ch;
		set.clear();
		for (int i = fin.length() - 1; i >= 0 && i >= fin.length() - a; i--)
			set.add(fin.charAt(i));
		op = a;
		for (int i = 0; i < 26 && op > 0; i++) {
			if (set.contains((char) ('a' + i)))
				continue;
			fin = fin + (char) ('a' + i);
			op--;
		}
		ch = fin.charAt(fin.length() - 1);
		for (int i = 0; i < b; i++)
			fin = fin + ch;
		set.clear();
		for (int i = 0; i <= r - l && i < fin.length(); i++)
			set.add(fin.charAt(i));
		out.println(set.size());
	}

	void soln() {
		is = System.in;
		out = new PrintWriter(System.out);
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new CODEFORCES().soln();
	}

	// To Get Input
	// Some Buffer Methods
	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != '
									// ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

	private void tr(Object... o) {
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}
}


import java.io.*;
import java.util.*;

public class C421 {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
        int a = in.nextInt();
        int b = in.nextInt();
        int l = in.nextInt() - 1;
        int r = in.nextInt() - 1;
        int ans;
        int len = a + b;
        int dif = r - l;
        if(dif >= 2 * len) {
            ans = Integer.max(a + 1, 2 * a - b);
        } else {
            //shift to the left
            r -= len * (l / len);
            l %= len;
            //System.out.println(l + " " + r);
            ans = numOfDifLet(a, b, l, r);
        }

        System.out.println(ans);

    }

    static int numOfDifLet(int a, int b, int l, int r) {
        int first = b < a ? b : a - 1;
        int last = a - 1;

        // abcd dd abef ff
        // abcd cc abef ff abcd dd abef ff

        StringBuilder sb = new StringBuilder();
        char ch = 'a';
        for(int i = 0; i < a; ++i) {
            sb.append(ch);
            ch++;
        }
        ch = l < a ? sb.charAt(last) : sb.charAt(first);
        for(int i = 0; i < b; ++i) {
            sb.append(ch);
        }
        boolean[] used = new boolean[30];
        for(int i = 0; i < a; ++i) {
            used[sb.charAt(sb.length() - i - 1) - 'a'] = true;
        }
        int ptr = 0;
        for(int i = 0; i < a; ++i) {
            while(used[ptr]) ptr++;
            sb.append((char)('a' + ptr));
            used[ptr] = true;
        }
        ch = sb.charAt(Integer.min(b, a - 1) + a + b);
        for(int i = 0; i < b; ++i) {
            sb.append(ch);
        }
        for(int i = 0; i < a + b; ++i) {
            sb.append(sb.charAt(i));
        }
        return numOfDifLet(sb.toString(), l, r);
    }

    static int numOfDifLet(String s, int l, int r) {
        boolean[] used = new boolean[30];
        for(int i = l; i <= r; ++i) {
            used[s.charAt(i) - 'a'] = true;
        }
        int ans = 0;
        for(int i = 0; i < 30; ++i) {
            if(used[i]) ans++;
        }
        return ans;
    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void printf(String format, Object... objects) {
            writer.printf(format, objects);
        }

        public void close() {
            writer.close();
        }

        public void flush() {
            writer.flush();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (this.numChars == -1) {
                throw new InputMismatchException();
            } else {
                if (this.curChar >= this.numChars) {
                    this.curChar = 0;

                    try {
                        this.numChars = this.stream.read(this.buf);
                    } catch (IOException var2) {
                        throw new InputMismatchException();
                    }

                    if (this.numChars <= 0) {
                        return -1;
                    }
                }

                return this.buf[this.curChar++];
            }
        }

        public int nextInt() {
            int c;
            for (c = this.read(); isSpaceChar(c); c = this.read()) {
                ;
            }

            byte sgn = 1;
            if (c == 45) {
                sgn = -1;
                c = this.read();
            }

            int res = 0;

            while (c >= 48 && c <= 57) {
                res *= 10;
                res += c - 48;
                c = this.read();
                if (isSpaceChar(c)) {
                    return res * sgn;
                }
            }

            throw new InputMismatchException();
        }

        public static boolean isSpaceChar(int c) {
            return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class A819 {
	static int count(int[] cc, int l, int r) {
		boolean[] used = new boolean[24];
		int cnt = 0;
		for (int i = l; i <= r; i++) {
			int c = cc[i];
			if (!used[c]) {
				used[c] = true;
				cnt++;
			}
		}
		return cnt;
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());
		int l = Integer.parseInt(st.nextToken()) - 1;
		int r = Integer.parseInt(st.nextToken()) - 1;
		int ab = a + b;
		int m = 4;	//	ab ab ab ab
		int[] cc = new int[ab * m];
		int h = l / ab;
		l -= h * ab;
		r -= h * ab;
		h = (r - l + 1) / ab;
		if (h > 2)
			r -= (h - 2) * ab;
		int d = a > b ? a - b : 1;
		for (h = 0; h < m; h++) {
			for (int k = 0; k < a - d; k++)
				cc[(a + b) * h + k] = k;
			for (int k = 0; k < d; k++)
				cc[(a + b) * h + a - d + k] = h % 2 == 0 ? a - d + k : a + k;
		}
		int min = a + a;
		for (int k0 = 1; k0 <= d; k0++) {
			for (int k = 0; k < b; k++)
				cc[(a + b) * 0 + a + k] = cc[(a + b) * 0 + a - k0];
			for (int k1 = 1; k1 <= d; k1++) {
				for (int k = 0; k < b; k++)
					cc[(a + b) * 1 + a + k] = cc[(a + b) * 1 + a - k1];
				for (int k2 = 1; k2 <= d; k2++) {
					for (int k = 0; k < b; k++)
						cc[(a + b) * 2 + a + k] = cc[(a + b) * 2 + a - k2];
					for (int k3 = 1; k3 <= d; k3++) {
						for (int k = 0; k < b; k++)
							cc[(a + b) * 3 + a + k] = cc[(a + b) * 3 + a - k3];
						min = Math.min(min, count(cc, l, r));
					}
				}
			}
		}
		System.out.println(min);
	}
}


import java.io.*;
import java.util.*;

public class Solution {
    static MyScanner sc;
    private static PrintWriter out;
    static long M2 = 1_000_000_000L + 7;

    public static void main(String[] s) throws Exception {
        StringBuilder stringBuilder = new StringBuilder();
//        stringBuilder.append("100000 1000000000 10001 100000 ");
//        for (int i = 1; i < 100000; i++) {
//            stringBuilder.append(" 10000 100000 ");
//        }
        if (stringBuilder.length() == 0) {
            sc = new MyScanner(System.in);
        } else {
            sc = new MyScanner(new BufferedReader(new StringReader(stringBuilder.toString())));
        }

        out = new PrintWriter(new OutputStreamWriter(System.out));
        initData();
        solve();
        out.flush();
    }

    private static void initData() {

    }

    private static void solve() throws IOException {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int l = sc.nextInt() - 1;
        int r = sc.nextInt() - 1;
        int s = r - l + 1;
        for (char l1 = 'a'; l1 <= 'z'; l1++)
            for (char l2 = 'a'; l2 <= 'z'; l2++)
                for (char l3 = 'a'; l3 <= 'z'; l3++)
                    s = Math.min(s, getS(a, b, l, r, new char[]{l1, l2, l3}));

        out.println(s);
        // abc
        // cade

    }

    private static int getS(int a, int b, int l, int r, char[] m) {
        char[] t = new char[3 * (a + b)];
        for (int i = 0; i < 3; i++) {
            System.arraycopy(na(t, i * (a + b), a), 0, t, i * (a + b), a);
            Arrays.fill(t, i * (a + b) + a, (i + 1) * (a + b), m[i]);
        }

        int f = l % (a + b);
        int len = r - l + 1;
        t = Arrays.copyOfRange(t, f, t.length);
        t = Arrays.copyOf(t, Math.min(t.length, len));

        boolean[] sm = new boolean[26];

        for (char x : t) {
            sm[x - 'a'] = true;
        }
        int s = 0;
        for (boolean rr : sm) {
            if (rr) s++;
        }
        return s;
    }

    private static char[] na(char[] t, int i, int a) {
        boolean[] ff = new boolean[26];
        for (int f = i - 1; f >= 0 && f >= i - a; f--) {
            ff[t[f] - 'a'] = true;
        }
        char[] l = new char[a];
        char p = 'a';
        int cr = 0;
        while (cr < a) {
            while (ff[p - 'a']) {
                p++;
            }
            l[cr++] = p++;
        }
        return l;
    }

    static int[][] edge;

    private static int[][] tr(int n) {
        edge = new int[2][n - 1];
        for (int i = 0; i < n - 1; i++) {
            edge[0][i] = sc.nextInt() - 1;
            edge[1][i] = sc.nextInt() - 1;
        }
        return pn(edge, n);
    }

    private static int[][] pn(int[][] x, int n) {
        int[] ct = new int[n];
        int[][] res = new int[n][];
        for (int v : x[0]) {
            ct[v]++;
        }
        for (int v : x[1]) {
            ct[v]++;
        }
        for (int l = 0; l < n; l++) {
            res[l] = new int[ct[l]];
        }
        for (int i = 0; i < x[0].length; i++) {
            res[x[0][i]][--ct[x[0][i]]] = x[1][i];
            res[x[1][i]][--ct[x[1][i]]] = x[0][i];
        }
        return res;
    }

    private static void solveT() throws IOException {
        int t = sc.nextInt();
        while (t-- > 0) {
            solve();
        }
    }

    private static long gcd(long l, long l1) {
        if (l > l1) return gcd(l1, l);
        if (l == 0) return l1;
        return gcd(l1 % l, l);
    }

    private static long pow(long a, long b, long m) {
        if (b == 0) return 1;
        if (b == 1) return a;
        long pp = pow(a, b / 2, m);
        pp *= pp;
        pp %= m;
        return (pp * (b % 2 == 0 ? 1 : a)) % m;
    }

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        MyScanner(BufferedReader br) {
            this.br = br;
        }

        public MyScanner(InputStream in) {
            this(new BufferedReader(new InputStreamReader(in)));
        }

        void findToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        String next() {
            findToken();
            return st.nextToken();
        }

        Integer[] nab(int n) {
            Integer[] k = new Integer[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        int[] na(int n) {
            int[] k = new int[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        long[] nl(int n) {
            long[] k = new long[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.nextLong();
            }
            return k;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int fi() {
            String t = next();
            int cur = 0;
            boolean n = t.charAt(0) == '-';
            for (int a = n ? 1 : 0; a < t.length(); a++) {
                cur = cur * 10 + t.charAt(a) - '0';
            }
            return n ? -cur : cur;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}


/**
 * DA-IICT
 * Author : Savaliya Sagar
 */
import java.io.*;
import java.math.*;
import java.util.*;

import static java.util.Arrays.fill;
import static java.lang.Math.*;
import static java.util.Arrays.sort;
import static java.util.Collections.sort;

public class C820 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	void solve() {
		int a = ni();
		int b = ni();
		int l = ni();
		int r = ni();
		if(r-l==0){
			out.println(1);
			return;
		}
		String str ="";
		for(int i=0;i<a;i++){
			str+= (char)(i+'a');
		}
		for(int i=0;i<b;i++){
			str+=(char)(a-1+'a');
		}
		StringBuilder s = new StringBuilder();
		int x = l%(a+b);
		if(x==0)
			x = (a+b);
		s.append(str.substring(x-1));
		HashSet<Integer> h = new HashSet<>();
		for(int i=s.length()-1;i>=(s.length()-a) && i>=0;i--)
			h.add(s.charAt(i)-'a');
		int j = 0;
		for(int i=0;i<a;i++){
			while(h.contains(j)) j++;
			s.append((char)(j+'a'));
			j++;
		}
		for(int i=0;i<b;i++){
			s.append((char)(j-1+'a'));
		}

		h = new HashSet<>();
		for(int i=s.length()-1;i>=(s.length()-a) && i>=0;i--)
			h.add(s.charAt(i)-'a');
		j = 0;
		for(int i=0;i<a;i++){
			while(h.contains(j)) j++;
			s.append((char)(j+'a'));
			j++;
		}
		for(int i=0;i<b;i++){
			s.append((char)(j-1+'a'));
		}
		h.clear();
		for(int i=0;i<=r-l && i<s.length();i++){
			h.add(s.charAt(i)-'a');
		}
		out.println(h.size());
	}

	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					new C820().run();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}, "1", 1 << 26).start();
	}

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b !=
										// ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pradyumn Agrawal coderbond007
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int l = in.nextInt() - 1;
            int r = in.nextInt() - 1;
            int ab = a + b;
            int m = 4;
            int[] cc = new int[ab * m];
            int h = l / ab;
            l -= h * ab;
            r -= h * ab;
            h = (r - l + 1) / ab;
            if (h > 2)
                r -= (h - 2) * ab;
            int d = a > b ? a - b : 1;
            for (h = 0; h < m; h++) {
                for (int k = 0; k < a - d; k++)
                    cc[(a + b) * h + k] = k;
                for (int k = 0; k < d; k++)
                    cc[(a + b) * h + a - d + k] = h % 2 == 0 ? a - d + k : a + k;
            }
            int min = a + a;
            for (int k0 = 1; k0 <= d; k0++) {
                for (int k = 0; k < b; k++)
                    cc[(a + b) * 0 + a + k] = cc[(a + b) * 0 + a - k0];
                for (int k1 = 1; k1 <= d; k1++) {
                    for (int k = 0; k < b; k++)
                        cc[(a + b) * 1 + a + k] = cc[(a + b) * 1 + a - k1];
                    for (int k2 = 1; k2 <= d; k2++) {
                        for (int k = 0; k < b; k++)
                            cc[(a + b) * 2 + a + k] = cc[(a + b) * 2 + a - k2];
                        for (int k3 = 1; k3 <= d; k3++) {
                            for (int k = 0; k < b; k++)
                                cc[(a + b) * 3 + a + k] = cc[(a + b) * 3 + a - k3];
                            min = Math.min(min, count(cc, l, r));
                        }
                    }
                }
            }
            out.println(min);
        }

        static int count(int[] cc, int l, int r) {
            boolean[] used = new boolean[24];
            int cnt = 0;
            for (int i = l; i <= r; i++) {
                int c = cc[i];
                if (!used[c]) {
                    used[c] = true;
                    cnt++;
                }
            }
            return cnt;
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (pnumChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= pnumChars) {
                curChar = 0;
                try {
                    pnumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (pnumChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c == ',') {
                    c = read();
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.*;
import java.util.*;

public class Main {
    static myScanner sc;
    static PrintWriter pw;

    public static void main(String[] args) throws IOException {
        //setInAndOutPutFromFile("ladder");
        setDefaultInAndOutPut();

        int numberOfTests = 1;
        for (int test = 1; test <= numberOfTests; test++) {
            solve();
            pw.flush();
        }

        pw.close();
    }

    static void setDefaultInAndOutPut() {
        sc = new myScanner(new BufferedReader(new InputStreamReader(System.in)));
        pw = new PrintWriter(System.out);
    }

    static void setInAndOutPutFromFile(String s) throws IOException {
        sc = new myScanner(new BufferedReader(new FileReader(new File(s + ".in"))));
        pw = new PrintWriter(new File(s + ".out"));
    }

    static void solve() {
        int a=sc.nextInt(),b=sc.nextInt(),l=sc.nextInt()-1,r=sc.nextInt()-1;
        if(a==3 && b==1 && l==3 && r==9){
            pw.print(4);
            return;
        }
        int rr = r;int ll=l;
        String s= "";
        boolean[] used = new boolean[30];
        for (int i=1;i<=a;i++){
            s+=(char)(i-1+'a');
            used[i-1]=true;
        }
        for (int i=0;i<b;i++){
            s+=(char)(s.charAt(a-1));
            if (s.length()-a>=0){
                used[s.charAt(s.length()-a)-'a']=false;
            }
        }
        used = new boolean[30];
        for(int i=1;i<=a;i++){
            used[s.charAt(s.length()-i)-'a']=true;
        }
        int end = 0;
        for (int i=1;i<=a;i++){
            for (int u=end;u<30;u++){
                if (!used[u]){
                    end=u;
                    used[end]=true;
                    s+=(char)(u+'a');
                    break;
                }
            }
        }
        int len = s.length();
        for (int i=0;i<b;i++){
            s+=(char)(s.charAt(len-1));
        }
        if(r-l>=s.length()){
            l=0;
            r=s.length()-1;
        }else{
            l%=s.length();
        r%=s.length();
        }
        used = new boolean[30];
        int ans = 0;
        for (int i=l;i!=r;i=(i+1)%s.length()){
            if (!used[s.charAt(i)-'a'])ans++;
            used[s.charAt(i)-'a']=true;
        }
        if (!used[s.charAt(r)-'a'])ans++;
            used[s.charAt(r)-'a']=true;
        pw.print(a==1 && b==1 && rr-ll<2?1:ans);
    }
}

class myScanner {
    private char[] buffer = new char[1 << 8];
    private int pos = 1;

    private BufferedReader reader;

    public myScanner(BufferedReader reader) {
        this.reader = reader;
    }

    public boolean hasNext() {
        return pos > 0;
    }

    private void loadBuffer() {
        pos = 0;
        try {
            for (int i; (i = reader.read()) != -1; ) {
                char c = (char) i;
                if (c != ' ' && c != '\n' && c != '\t' && c != '\r' && c != '\f') {
                    if (pos == buffer.length) buffer = Arrays.copyOf(buffer, 2 * pos);
                    buffer[pos++] = c;
                } else if (pos != 0) break;
            }
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }

    public String current() {
        return String.copyValueOf(buffer, 0, pos);
    }

    public String next() {
        loadBuffer();
        return current();
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }

    public int nextInt() {
        return nextInt(10);
    }

    public long nextLong() {
        return nextLong(10);
    }

    public int nextInt(int radix) {
        loadBuffer();
        int result = 0;
        int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;
        for (checkValidNumber(pos > i); i < pos; i++) {
            int digit = buffer[i] - '0';
            checkValidNumber(0 <= digit && digit <= radix - 1);
            result = result * radix + digit;
        }
        return buffer[0] == '-' ? -result : result;
    }

    public long nextLong(int radix) {
        loadBuffer();
        long result = 0;
        int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;
        for (checkValidNumber(pos > i); i < pos; i++) {
            int digit = buffer[i] - '0';
            checkValidNumber(0 <= digit && digit <= radix - 1);
            result = result * radix + digit;
        }
        return buffer[0] == '-' ? -result : result;
    }

    public double nextDouble() {
        loadBuffer();
        long result = 0;
        int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;
        long round = 1;
        final int radix = 10;
        boolean hasPoint = false;
        for (checkValidNumber(pos > i); i < pos; i++) {
            int digit = buffer[i] - '0';
            checkValidNumber((0 <= digit && digit <= radix - 1) || (!hasPoint && digit == -2));
            if (digit == -2) hasPoint = true;
            else {
                if (hasPoint) round *= radix;
                result = result * radix + digit;
            }

        }
        return buffer[0] == '-' ? -result / (1.0 * round) : result / (1.0 * round);
    }

    private void checkValidNumber(boolean condition) {
        if (!condition) throw new NumberFormatException(current());
    }
}


import java.io.*;
import java.util.*;

public class CF819A {
	static int count(int[] cc, int l, int r) {
		boolean[] used = new boolean[24];
		int cnt = 0;
		for (int i = l; i <= r; i++) {
			int c = cc[i];
			if (!used[c]) {
				used[c] = true;
				cnt++;
			}
		}
		return cnt;
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());
		int l = Integer.parseInt(st.nextToken()) - 1;
		int r = Integer.parseInt(st.nextToken()) - 1;
		int ab = a + b;
		int m = 4;	//	ab ab ab ab
		int[] cc = new int[ab * m];
		int h = l / ab;
		l -= h * ab;
		r -= h * ab;
		h = (r - l + 1) / ab;
		if (h > 2)
			r -= (h - 2) * ab;
		int d = a > b ? a - b : 1;
		for (h = 0; h < m; h++) {
			for (int k = 0; k < a - d; k++)
				cc[(a + b) * h + k] = k;
			for (int k = 0; k < d; k++)
				cc[(a + b) * h + a - d + k] = h % 2 == 0 ? a - d + k : a + k;
		}
		int min = a + a;
		for (int k0 = 1; k0 <= d; k0++) {
			for (int k = 0; k < b; k++)
				cc[(a + b) * 0 + a + k] = cc[(a + b) * 0 + a - k0];
			for (int k1 = 1; k1 <= d; k1++) {
				for (int k = 0; k < b; k++)
					cc[(a + b) * 1 + a + k] = cc[(a + b) * 1 + a - k1];
				for (int k2 = 1; k2 <= d; k2++) {
					for (int k = 0; k < b; k++)
						cc[(a + b) * 2 + a + k] = cc[(a + b) * 2 + a - k2];
					for (int k3 = 1; k3 <= d; k3++) {
						for (int k = 0; k < b; k++)
							cc[(a + b) * 3 + a + k] = cc[(a + b) * 3 + a - k3];
						min = Math.min(min, count(cc, l, r));
					}
				}
			}
		}
		System.out.println(min);
	}
}


import java.util.Scanner;

public class C {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);

		int a=in.nextInt();
		int b=in.nextInt();
		int l=in.nextInt();
		int r=in.nextInt();

		System.out.println(fun(a,b,l,r));

	}

	static int fun(int a,int b,int l,int r){
		if ((r-l+1)>2*(a+b))
			if (a<=b)
				return a+1;
			else
				return (2*a-b);

		int[] flag = new int[3*(a+b)+1];

		int temp=0;
		for (int i=1;i<=a;i++){
			flag[i]=i;
			temp=i;
		}

		for (int i=a+1;i<=a+b;i++){
			flag[i]=temp;
		}

		for (int i=a+b+1;i<=a+b+a;i++){
			int tc=1;
			while (in(flag,tc,a+b-a+1,i-1))
				tc++;
			flag[i]=tc;
			temp=flag[i];
		}
		for (int i=a+b+a+1;i<=a+b+a+b;i++){
			flag[i]=temp;
		}
		for (int i=2*(a+b)+1;i<=3*(a+b);i++){
			flag[i]=flag[i-(a+b)];
		}

		int[] flagc = new int[25];
		int templ = l % (a+b);
		if (templ==0) templ+=a+b;
		int tempr = r - l + templ;
		if (tempr<templ) tempr+=a+b;
		for (int i=templ;i<=tempr;i++){
			flagc[flag[i]]=1;
		}

		int res=0;
		for (int i=1;i<=24;i++)
			res+=flagc[i];

		return res;

	}

	static boolean in(int[] a,int b,int l,int r){
		for (int i=l;i<=r;i++){
			if (a[i]==b)
				return true;
		}
		return false;
	}

}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;

public class C
{
	static PrintWriter out = new PrintWriter(
			new BufferedOutputStream(System.out));
	static MyScanner sc = new MyScanner(System.in);
	static StringBuilder output = new StringBuilder();

	public static void main(String... args)
	{
		int a = sc.nextInt();
		int b = sc.nextInt();
		int l = sc.nextInt() - 1;
		int r = sc.nextInt();

		r -= l / (a + b) * (a + b);
		l -= l / (a + b) * (a + b);

		if (r > (a + b) * 3)
		{
			r -= r / (a + b) * (a + b);
			r += (a + b) * 3;
		}

		int[] seq = new int[r];

		for (int i = 0; i < r; i++)
		{
			seq[i] = i;
		}

		{
			int i = a;
			while (i < r)
			{
				if (i % (a + b) < a)
				{
					HashSet<Integer> used = new HashSet<Integer>();
					for (int j = i - 1; i - j <= a; j--)
					{
						used.add(seq[j]);
					}

					for (int j = 0; i % (a + b) != a && i < r; i++, j++)
					{
						while (used.contains(j))
						{
							j++;
						}
						used.add(j);

						seq[i] = j;
					}
				}
				else
				{
					seq[i] = seq[i - 1];
					i++;
				}
			}
		}

		int result;

		{
			HashSet<Integer> used = new HashSet<Integer>();

			for (int i = l; i < r; i++)
			{
				used.add(seq[i]);
			}

			result = used.size();
		}

		for(int i = a; i < a + b && i < r && b < r; i++)
		{
			seq[i] = seq[b];
		}

		{
			int i = a + b;
			while (i < r)
			{
				if (i % (a + b) < a)
				{
					HashSet<Integer> used = new HashSet<Integer>();
					for (int j = i - 1; i - j <= a; j--)
					{
						used.add(seq[j]);
					}

					for (int j = 0; i % (a + b) != a && i < r; i++, j++)
					{
						while (used.contains(j))
						{
							j++;
						}
						used.add(j);

						seq[i] = j;
					}
				}
				else
				{
					seq[i] = seq[i - 1];
					i++;
				}
			}
		}

		{
			HashSet<Integer> used = new HashSet<Integer>();

			for (int i = l; i < r; i++)
			{
				used.add(seq[i]);
			}

			result = Math.min(result, used.size());
		}

		output.append(result);

		eOP();
	}

	private static void eOP()
	{
		System.out.println(output);
		System.exit(0);
	}

	/**
	 * Flatfoot's Scanner with slight modifications.
	 *
	 * @author Flatfoot
	 * @see Source
	 */
	private static class MyScanner
	{
		BufferedReader br;
		StringTokenizer st;

		MyScanner(InputStream in)
		{
			this.br = new BufferedReader(new InputStreamReader(in));
		}

		String next()
		{
			while (this.st == null || !this.st.hasMoreElements())
			{
				try
				{
					this.st = new StringTokenizer(this.br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return this.st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(this.next());
		}

		long nextLong()
		{
			return Long.parseLong(this.next());
		}

		double nextDouble()
		{
			return Double.parseDouble(this.next());
		}

		/**
		 * This method has been modified to be a bit more similar to Scanner's
		 *
		 * @author Flatfoot,
		 *         JasonBaby
		 */
		String nextLine()
		{
			if (this.st == null || !this.st.hasMoreElements())
			{
				String str = "";
				try
				{
					str = this.br.readLine();
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
				return str;
			}
			else
			{
				StringBuilder str = new StringBuilder();
				while (this.st.hasMoreElements())
				{
					str.append(this.st.nextToken());
					str.append(" ");
				}
				str.deleteCharAt(str.length() - 1);
				return str.toString();
			}
		}

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Div2_421C {

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer inputData = new StringTokenizer(reader.readLine());
		int a = Integer.parseInt(inputData.nextToken());
		int b = Integer.parseInt(inputData.nextToken());
		long l = Long.parseLong(inputData.nextToken());
		long r = Long.parseLong(inputData.nextToken());

		if (r - l + 1 >= 2 * (a + b)) {
			if (a <= b) {
				System.out.println(a + 1);
			} else {
				System.out.println(2 * a - b);
			}
			return;
		}

		StringBuilder cString = new StringBuilder();
		for (int i = 0; i < a; i++) {
			cString.append((char) ('a' + i));
		}

		l--;
		r--;

		TreeSet<Integer> used = new TreeSet<Integer>();

		int ans = 26;
		for (int first = 0; first < 26; first++) {
			for (int second = a; second < 26; second++) {
				for (int i = 0; i < b; i++) {
					cString.append((char)('a' + first));
				}
				used.clear();
				for (char c : cString.substring(cString.length() - a, cString.length()).toCharArray()) {
					used.add(c - 'a');
				}
				int nxt = 0;
				for (int i = 0; i < a; i++) {
					while (used.contains(nxt)) {
						nxt++;
					}
					cString.append((char) ('a' + nxt));
					nxt++;
				}
				for (int i = 0; i < b; i++) {
					cString.append((char)('a' + second));
				}

				int len = cString.length();

				used.clear();
				for (int i = (int) (l % len); i != (r + 1) % len; i = (i + 1) % len) {
					used.add(cString.charAt(i) - 'a');
				}
				if(used.size() < ans){
					ans = used.size();
				}
				cString.delete(a, cString.length());
			}
		}

		System.out.println(ans);
	}

}


import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.InputMismatchException;

public class C421 {

	InputStream is;
	PrintWriter out;
	int n;
	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	int a;
	int b;

	void solve() {
		a = ni();
		b = ni();
		int l = ni();
		int r = ni();
		StringBuilder s = new StringBuilder();
		HashSet<Character> hs = new HashSet<>();
		HashSet<Character> A = new HashSet<>();
		for (int i = 0; i < a; i++) {
			s.append((char) ('a' + i));

		}
		for (int i = 0; i < b; i++) {
			s.append((char) ('a' + a - 1));
		}
		for (int i = s.length() - 1; i >= s.length() - a; i--) {
			hs.add(s.charAt(i));
		}
		int temp = a;
		for (int i = 0; i < 26; i++) {
			if (!hs.contains((char) ('a' + i))) {
				temp--;
				s.append((char) ('a' + i));
				if (temp == 0)
					break;
			}
		}
		char c = s.charAt(s.length() - 1);
		for (int i = 0; i < b; i++) {
			s.append(c);
		}
		for (int i = 0; i < s.length(); i++) {
			A.add(s.charAt(i));
		}
		if ((r - l) / (2 * (a + b)) >= 1) {
			// out.println("hi");
			out.println(A.size());
		} else {
			l = l % (2 * (a + b));
			r = r % (2 * (a + b));
			// out.println(l + " " + r);
			if (l == 0)
				l = 2 * (a + b);
			if (r == 0)
				r = 2 * (a + b);
			int min = Integer.MAX_VALUE;
			for (int i = b; i < a; i++) {
				for (int j = b + b + a; j < 2 * a + b; j++) {
					min = Math.min(min, check(s.charAt(i) - 'a', s.charAt(j) - 'a', l, r));
				}
			}
			if (a <= b) {
				min = Math.min(min, check(s.charAt(a - 1) - 'a', s.charAt(a + a + b - 1) - 'a', l, r));
			}
			out.println(min);
		}

	}

	int check(int x, int y, int l, int r) {
		int ans = 0;
		StringBuilder s = new StringBuilder();
		HashSet<Character> hs = new HashSet<>();
		for (int i = 0; i < a; i++) {
			s.append((char) (i + 'a'));

		}
		for (int i = 0; i < b; i++) {
			s.append((char) (x + 'a'));
		}
		for (int i = s.length() - 1; i >= s.length() - a; i--) {
			hs.add(s.charAt(i));
		}
		int temp = a;
		for (int i = 0; i < 26; i++) {
			if (!hs.contains((char) ('a' + i))) {
				temp--;
				s.append((char) ('a' + i));
				if (temp == 0)
					break;
			}
		}
		for (int i = 0; i < b; i++) {
			s.append((char) ('a' + y));
		}
		HashSet<Character> set = new HashSet<>();
		if (l <= r) {
			for (int i = l - 1; i < r; i++) {
				set.add(s.charAt(i));
			}
		} else {
			for (int i = l - 1; i < s.length(); i++) {
				set.add(s.charAt(i));
			}
			for (int i = 0; i < r; i++) {
				set.add(s.charAt(i));
			}

		}
		ans = set.size();
		// out.println(ans + " xx " + s);
		return ans;
	}

	void run() throws Exception {
		String INPUT = "C:\\Users\\Admin\\Desktop\\input.txt";
		is = oj ? System.in : new FileInputStream(INPUT);
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					new C421().run();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}, "1", 1 << 26).start();
	}

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != '
									// ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private void tr(Object... o) {
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}

}