import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int one = Integer.parseInt(sc.next());
		int zero = Integer.parseInt(sc.next());
		int min = Integer.parseInt(sc.next());
		int count = Integer.parseInt(sc.next());
		int time = 0;
		if(count==0) {
			System.out.println(0);
		}
		else if(one+zero>=count) {
			if(one>=count) {
			System.out.println(count);}else {
				System.out.println(one);
			}
		}else {
			int mins = count -one-zero;
			System.out.println(one-mins);
		}
}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int one = Integer.parseInt(sc.next());
		int zero = Integer.parseInt(sc.next());
		int min = Integer.parseInt(sc.next());
		int count = Integer.parseInt(sc.next());
		int time = 0;
		if(count==0) {
			System.out.println(0);
		}
		else if(one+zero>=count) {
			if(one>=count) {
			System.out.println(count);}else {
				System.out.println(one);
			}
		}else {
			int mins = count -one-zero;
			System.out.println(one-mins);
		}
}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int one = Integer.parseInt(sc.next());
		int zero = Integer.parseInt(sc.next());
		int min = Integer.parseInt(sc.next());
		int count = Integer.parseInt(sc.next());
		int time = 0;
		if(count==0) {
			System.out.println(0);
		}
		else if(one+zero>=count) {
			if(one>=count) {
			System.out.println(count);}else {
				System.out.println(one);
			}
		}else {
			int mins = count -one-zero;
			System.out.println(one-mins);
		}
} main {
		Scanner sc = new Scanner(System.in);
		int one = Integer.parseInt(sc.next());
		int zero = Integer.parseInt(sc.next());
		int min = Integer.parseInt(sc.next());
		int count = Integer.parseInt(sc.next());
		int time = 0;
		if(count==0) {
			System.out.println(0);
		}
		else if(one+zero>=count) {
			if(one>=count) {
			System.out.println(count);}else {
				System.out.println(one);
			}
		}else {
			int mins = count -one-zero;
			System.out.println(one-mins);
		}
} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int one = Integer.parseInt(sc.next()); one Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int zero = Integer.parseInt(sc.next()); zero Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int min = Integer.parseInt(sc.next()); min Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int count = Integer.parseInt(sc.next()); count Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int time = 0; time 0 if(count==0) {
			System.out.println(0);
		}
		else if(one+zero>=count) {
			if(one>=count) {
			System.out.println(count);}else {
				System.out.println(one);
			}
		}else {
			int mins = count -one-zero;
			System.out.println(one-mins);
		} count==0 count 0 {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 if(one+zero>=count) {
			if(one>=count) {
			System.out.println(count);}else {
				System.out.println(one);
			}
		}else {
			int mins = count -one-zero;
			System.out.println(one-mins);
		} one+zero>=count one+zero one zero count {
			if(one>=count) {
			System.out.println(count);}else {
				System.out.println(one);
			}
		} if(one>=count) {
			System.out.println(count);}else {
				System.out.println(one);
			} one>=count one count {
			System.out.println(count);} System.out.println(count) System.out.println System.out System System.out count {
				System.out.println(one);
			} System.out.println(one) System.out.println System.out System System.out one {
			int mins = count -one-zero;
			System.out.println(one-mins);
		} int mins = count -one-zero; mins count -one-zero count -one-zero count one zero System.out.println(one-mins) System.out.println System.out System System.out one-mins one mins String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int one = Integer.parseInt(sc.next());
		int zero = Integer.parseInt(sc.next());
		int min = Integer.parseInt(sc.next());
		int count = Integer.parseInt(sc.next());
		int time = 0;
		if(count==0) {
			System.out.println(0);
		}
		else if(one+zero>=count) {
			if(one>=count) {
			System.out.println(count);}else {
				System.out.println(one);
			}
		}else {
			int mins = count -one-zero;
			System.out.println(one-mins);
		}
}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int one = Integer.parseInt(sc.next());
		int zero = Integer.parseInt(sc.next());
		int min = Integer.parseInt(sc.next());
		int count = Integer.parseInt(sc.next());
		int time = 0;
		if(count==0) {
			System.out.println(0);
		}
		else if(one+zero>=count) {
			if(one>=count) {
			System.out.println(count);}else {
				System.out.println(one);
			}
		}else {
			int mins = count -one-zero;
			System.out.println(one-mins);
		}
}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int one = Integer.parseInt(sc.next());
		int zero = Integer.parseInt(sc.next());
		int min = Integer.parseInt(sc.next());
		int count = Integer.parseInt(sc.next());
		int time = 0;
		if(count==0) {
			System.out.println(0);
		}
		else if(one+zero>=count) {
			if(one>=count) {
			System.out.println(count);}else {
				System.out.println(one);
			}
		}else {
			int mins = count -one-zero;
			System.out.println(one-mins);
		}
}
}
