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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author EDGE
 */
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);
        BEasyLinearProgramming solver = new BEasyLinearProgramming();
        solver.solve(1, in, out);
        out.close();
    }

    static class BEasyLinearProgramming {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int a, b, c, d;
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            d = in.nextInt();
            if (d <= a) {
                out.println(d);
                return;
            }

            d = d - a;
            if (d - b <= 0) {
                out.println(a);
                return;
            }
            d = d - b;
            out.println(a - d);

        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

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

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

    }
}
 import java.io.OutputStream; OutputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.StringTokenizer; StringTokenizer java.util import java.io.IOException; IOException java.io import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.InputStream; InputStream java.io 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);
        BEasyLinearProgramming solver = new BEasyLinearProgramming();
        solver.solve(1, in, out);
        out.close();
    }

    static class BEasyLinearProgramming {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int a, b, c, d;
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            d = in.nextInt();
            if (d <= a) {
                out.println(d);
                return;
            }

            d = d - a;
            if (d - b <= 0) {
                out.println(a);
                return;
            }
            d = d - b;
            out.println(a - d);

        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

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

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

    }
} 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);
        BEasyLinearProgramming solver = new BEasyLinearProgramming();
        solver.solve(1, in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BEasyLinearProgramming solver = new BEasyLinearProgramming();
        solver.solve(1, in, out);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out FastReader in = new FastReader(inputStream); in new FastReader(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) BEasyLinearProgramming solver = new BEasyLinearProgramming(); solver new BEasyLinearProgramming() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class BEasyLinearProgramming {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int a, b, c, d;
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            d = in.nextInt();
            if (d <= a) {
                out.println(d);
                return;
            }

            d = d - a;
            if (d - b <= 0) {
                out.println(a);
                return;
            }
            d = d - b;
            out.println(a - d);

        }

    } BEasyLinearProgramming public void solve(int testNumber, FastReader in, PrintWriter out) {
            int a, b, c, d;
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            d = in.nextInt();
            if (d <= a) {
                out.println(d);
                return;
            }

            d = d - a;
            if (d - b <= 0) {
                out.println(a);
                return;
            }
            d = d - b;
            out.println(a - d);

        } solve {
            int a, b, c, d;
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            d = in.nextInt();
            if (d <= a) {
                out.println(d);
                return;
            }

            d = d - a;
            if (d - b <= 0) {
                out.println(a);
                return;
            }
            d = d - b;
            out.println(a - d);

        } int a a b b c c d; d a = in.nextInt() a in.nextInt() in.nextInt in b = in.nextInt() b in.nextInt() in.nextInt in c = in.nextInt() c in.nextInt() in.nextInt in d = in.nextInt() d in.nextInt() in.nextInt in if (d <= a) {
                out.println(d);
                return;
            } d <= a d a {
                out.println(d);
                return;
            } out.println(d) out.println out d return; d = d - a d d - a d a if (d - b <= 0) {
                out.println(a);
                return;
            } d - b <= 0 d - b d b 0 {
                out.println(a);
                return;
            } out.println(a) out.println out a return; d = d - b d d - b d b out.println(a - d) out.println out a - d a d int testNumber testNumber FastReader in in PrintWriter out out static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

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

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

    } FastReader BufferedReader br; br StringTokenizer st; st public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        } FastReader {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        } br = new BufferedReader(new
                    InputStreamReader(inputStream)) br new BufferedReader(new
                    InputStreamReader(inputStream)) InputStream inputStream inputStream String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        } next {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        } while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } st == null || !st.hasMoreElements() st == null st null !st.hasMoreElements() st.hasMoreElements() st.hasMoreElements st {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } IOException e {
                    e.printStackTrace();
                } e.printStackTrace() e.printStackTrace e {
                    st = new StringTokenizer(br.readLine());
                } st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st public int nextInt() {
            return Integer.parseInt(next());
        } nextInt {
            return Integer.parseInt(next());
        } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next 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);
        BEasyLinearProgramming solver = new BEasyLinearProgramming();
        solver.solve(1, in, out);
        out.close();
    }

    static class BEasyLinearProgramming {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int a, b, c, d;
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            d = in.nextInt();
            if (d <= a) {
                out.println(d);
                return;
            }

            d = d - a;
            if (d - b <= 0) {
                out.println(a);
                return;
            }
            d = d - b;
            out.println(a - d);

        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

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

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

    }
} 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);
        BEasyLinearProgramming solver = new BEasyLinearProgramming();
        solver.solve(1, in, out);
        out.close();
    }

    static class BEasyLinearProgramming {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int a, b, c, d;
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            d = in.nextInt();
            if (d <= a) {
                out.println(d);
                return;
            }

            d = d - a;
            if (d - b <= 0) {
                out.println(a);
                return;
            }
            d = d - b;
            out.println(a - d);

        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

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

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

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author EDGE
 */
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);
        BEasyLinearProgramming solver = new BEasyLinearProgramming();
        solver.solve(1, in, out);
        out.close();
    }

    static class BEasyLinearProgramming {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int a, b, c, d;
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            d = in.nextInt();
            if (d <= a) {
                out.println(d);
                return;
            }

            d = d - a;
            if (d - b <= 0) {
                out.println(a);
                return;
            }
            d = d - b;
            out.println(a - d);

        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

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

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

    }
}

