import java.io.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        String[] arr = reader.readLine().split (" ");
        int A = Integer.parseInt (arr[0]);
        int B = Integer.parseInt (arr[1]);
        int K = Integer.parseInt (arr[3]);
        if (K <= A)
            System.out.println (K);
        else if (K <= A + B)
            System.out.println (A);
        else
            System.out.println (A - (K - A - B));
        return;
    }
} import java.io.*; io.* java public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        String[] arr = reader.readLine().split (" ");
        int A = Integer.parseInt (arr[0]);
        int B = Integer.parseInt (arr[1]);
        int K = Integer.parseInt (arr[3]);
        if (K <= A)
            System.out.println (K);
        else if (K <= A + B)
            System.out.println (A);
        else
            System.out.println (A - (K - A - B));
        return;
    }
} Main public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        String[] arr = reader.readLine().split (" ");
        int A = Integer.parseInt (arr[0]);
        int B = Integer.parseInt (arr[1]);
        int K = Integer.parseInt (arr[3]);
        if (K <= A)
            System.out.println (K);
        else if (K <= A + B)
            System.out.println (A);
        else
            System.out.println (A - (K - A - B));
        return;
    } main {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        String[] arr = reader.readLine().split (" ");
        int A = Integer.parseInt (arr[0]);
        int B = Integer.parseInt (arr[1]);
        int K = Integer.parseInt (arr[3]);
        if (K <= A)
            System.out.println (K);
        else if (K <= A + B)
            System.out.println (A);
        else
            System.out.println (A - (K - A - B));
        return;
    } BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in)); reader new BufferedReader (new InputStreamReader (System.in)) String[] arr = reader.readLine().split (" "); arr reader.readLine().split (" ") reader.readLine().split reader.readLine() reader.readLine reader " " int A = Integer.parseInt (arr[0]); A Integer.parseInt (arr[0]) Integer.parseInt Integer arr[0] arr 0 int B = Integer.parseInt (arr[1]); B Integer.parseInt (arr[1]) Integer.parseInt Integer arr[1] arr 1 int K = Integer.parseInt (arr[3]); K Integer.parseInt (arr[3]) Integer.parseInt Integer arr[3] arr 3 if (K <= A)
            System.out.println (K);
        else if (K <= A + B)
            System.out.println (A);
        else
            System.out.println (A - (K - A - B)); K <= A K A System.out.println (K) System.out.println System.out System System.out K if (K <= A + B)
            System.out.println (A);
        else
            System.out.println (A - (K - A - B)); K <= A + B K A + B A B System.out.println (A) System.out.println System.out System System.out A System.out.println (A - (K - A - B)) System.out.println System.out System System.out A - (K - A - B) A (K - A - B) K - A - B K A B return; String[] args args public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        String[] arr = reader.readLine().split (" ");
        int A = Integer.parseInt (arr[0]);
        int B = Integer.parseInt (arr[1]);
        int K = Integer.parseInt (arr[3]);
        if (K <= A)
            System.out.println (K);
        else if (K <= A + B)
            System.out.println (A);
        else
            System.out.println (A - (K - A - B));
        return;
    }
} public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        String[] arr = reader.readLine().split (" ");
        int A = Integer.parseInt (arr[0]);
        int B = Integer.parseInt (arr[1]);
        int K = Integer.parseInt (arr[3]);
        if (K <= A)
            System.out.println (K);
        else if (K <= A + B)
            System.out.println (A);
        else
            System.out.println (A - (K - A - B));
        return;
    }
} Main
import java.io.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        String[] arr = reader.readLine().split (" ");
        int A = Integer.parseInt (arr[0]);
        int B = Integer.parseInt (arr[1]);
        int K = Integer.parseInt (arr[3]);
        if (K <= A)
            System.out.println (K);
        else if (K <= A + B)
            System.out.println (A);
        else
            System.out.println (A - (K - A - B));
        return;
    }
}