import java.util.Scanner;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int N2 = Integer.parseInt(sc.next());
    int N3 = Integer.parseInt(sc.next());
    int N4 = Integer.parseInt(sc.next());
    if(N4-N <= 0) {
    	System.out.println(N4*1);
    } else if((N4-N) - N2 <= 0) {
    	System.out.println(N*1);
    } else {
    	System.out.println(N*1 + (-1 * ((N4-N) - N2)));
    }

  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int N2 = Integer.parseInt(sc.next());
    int N3 = Integer.parseInt(sc.next());
    int N4 = Integer.parseInt(sc.next());
    if(N4-N <= 0) {
    	System.out.println(N4*1);
    } else if((N4-N) - N2 <= 0) {
    	System.out.println(N*1);
    } else {
    	System.out.println(N*1 + (-1 * ((N4-N) - N2)));
    }

  }
} Main public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int N2 = Integer.parseInt(sc.next());
    int N3 = Integer.parseInt(sc.next());
    int N4 = Integer.parseInt(sc.next());
    if(N4-N <= 0) {
    	System.out.println(N4*1);
    } else if((N4-N) - N2 <= 0) {
    	System.out.println(N*1);
    } else {
    	System.out.println(N*1 + (-1 * ((N4-N) - N2)));
    }

  } main {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int N2 = Integer.parseInt(sc.next());
    int N3 = Integer.parseInt(sc.next());
    int N4 = Integer.parseInt(sc.next());
    if(N4-N <= 0) {
    	System.out.println(N4*1);
    } else if((N4-N) - N2 <= 0) {
    	System.out.println(N*1);
    } else {
    	System.out.println(N*1 + (-1 * ((N4-N) - N2)));
    }

  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int N2 = Integer.parseInt(sc.next()); N2 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int N3 = Integer.parseInt(sc.next()); N3 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int N4 = Integer.parseInt(sc.next()); N4 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if(N4-N <= 0) {
    	System.out.println(N4*1);
    } else if((N4-N) - N2 <= 0) {
    	System.out.println(N*1);
    } else {
    	System.out.println(N*1 + (-1 * ((N4-N) - N2)));
    } N4-N <= 0 N4-N N4 N 0 {
    	System.out.println(N4*1);
    } System.out.println(N4*1) System.out.println System.out System System.out N4*1 N4 1 if((N4-N) - N2 <= 0) {
    	System.out.println(N*1);
    } else {
    	System.out.println(N*1 + (-1 * ((N4-N) - N2)));
    } (N4-N) - N2 <= 0 (N4-N) - N2 (N4-N) N4 N N2 0 {
    	System.out.println(N*1);
    } System.out.println(N*1) System.out.println System.out System System.out N*1 N 1 {
    	System.out.println(N*1 + (-1 * ((N4-N) - N2)));
    } System.out.println(N*1 + (-1 * ((N4-N) - N2))) System.out.println System.out System System.out N*1 + (-1 * ((N4-N) - N2)) N*1 N 1 (-1 * ((N4-N) - N2)) -1 1 ((N4-N) - N2) (N4-N) N4 N N2 String[] args args public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int N2 = Integer.parseInt(sc.next());
    int N3 = Integer.parseInt(sc.next());
    int N4 = Integer.parseInt(sc.next());
    if(N4-N <= 0) {
    	System.out.println(N4*1);
    } else if((N4-N) - N2 <= 0) {
    	System.out.println(N*1);
    } else {
    	System.out.println(N*1 + (-1 * ((N4-N) - N2)));
    }

  }
} public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int N2 = Integer.parseInt(sc.next());
    int N3 = Integer.parseInt(sc.next());
    int N4 = Integer.parseInt(sc.next());
    if(N4-N <= 0) {
    	System.out.println(N4*1);
    } else if((N4-N) - N2 <= 0) {
    	System.out.println(N*1);
    } else {
    	System.out.println(N*1 + (-1 * ((N4-N) - N2)));
    }

  }
} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int N2 = Integer.parseInt(sc.next());
    int N3 = Integer.parseInt(sc.next());
    int N4 = Integer.parseInt(sc.next());
    if(N4-N <= 0) {
    	System.out.println(N4*1);
    } else if((N4-N) - N2 <= 0) {
    	System.out.println(N*1);
    } else {
    	System.out.println(N*1 + (-1 * ((N4-N) - N2)));
    }

  }
}