import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
       int A =sc.nextInt();
      int B =sc.nextInt();
      int C =sc.nextInt();
      int K =sc.nextInt();
      
      for(int i=1; i<=K; i++){
      if(K-A==0){
      System.out.println(A*1);
        return;
      }
        if(K-A<0){
        System.out.println(K*1);
          return;
        }
        if((K-A)-B<=0){
         System.out.println(A*1+B*0);
          return;
        }
        if((K-A)-B>0){
        System.out.println(A*1+B*0+(((K-A)-B)*(-1)));
          return;
        }
      }
    }
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
       int A =sc.nextInt();
      int B =sc.nextInt();
      int C =sc.nextInt();
      int K =sc.nextInt();
      
      for(int i=1; i<=K; i++){
      if(K-A==0){
      System.out.println(A*1);
        return;
      }
        if(K-A<0){
        System.out.println(K*1);
          return;
        }
        if((K-A)-B<=0){
         System.out.println(A*1+B*0);
          return;
        }
        if((K-A)-B>0){
        System.out.println(A*1+B*0+(((K-A)-B)*(-1)));
          return;
        }
      }
    }
} Main public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
       int A =sc.nextInt();
      int B =sc.nextInt();
      int C =sc.nextInt();
      int K =sc.nextInt();
      
      for(int i=1; i<=K; i++){
      if(K-A==0){
      System.out.println(A*1);
        return;
      }
        if(K-A<0){
        System.out.println(K*1);
          return;
        }
        if((K-A)-B<=0){
         System.out.println(A*1+B*0);
          return;
        }
        if((K-A)-B>0){
        System.out.println(A*1+B*0+(((K-A)-B)*(-1)));
          return;
        }
      }
    } main {
      Scanner sc = new Scanner(System.in);
       int A =sc.nextInt();
      int B =sc.nextInt();
      int C =sc.nextInt();
      int K =sc.nextInt();
      
      for(int i=1; i<=K; i++){
      if(K-A==0){
      System.out.println(A*1);
        return;
      }
        if(K-A<0){
        System.out.println(K*1);
          return;
        }
        if((K-A)-B<=0){
         System.out.println(A*1+B*0);
          return;
        }
        if((K-A)-B>0){
        System.out.println(A*1+B*0+(((K-A)-B)*(-1)));
          return;
        }
      }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int A =sc.nextInt(); A sc.nextInt() sc.nextInt sc int B =sc.nextInt(); B sc.nextInt() sc.nextInt sc int C =sc.nextInt(); C sc.nextInt() sc.nextInt sc int K =sc.nextInt(); K sc.nextInt() sc.nextInt sc for(int i=1; i<=K; i++){
      if(K-A==0){
      System.out.println(A*1);
        return;
      }
        if(K-A<0){
        System.out.println(K*1);
          return;
        }
        if((K-A)-B<=0){
         System.out.println(A*1+B*0);
          return;
        }
        if((K-A)-B>0){
        System.out.println(A*1+B*0+(((K-A)-B)*(-1)));
          return;
        }
      } int i=1; int i=1; i 1 i<=K i K i++ i++ i {
      if(K-A==0){
      System.out.println(A*1);
        return;
      }
        if(K-A<0){
        System.out.println(K*1);
          return;
        }
        if((K-A)-B<=0){
         System.out.println(A*1+B*0);
          return;
        }
        if((K-A)-B>0){
        System.out.println(A*1+B*0+(((K-A)-B)*(-1)));
          return;
        }
      } {
      if(K-A==0){
      System.out.println(A*1);
        return;
      }
        if(K-A<0){
        System.out.println(K*1);
          return;
        }
        if((K-A)-B<=0){
         System.out.println(A*1+B*0);
          return;
        }
        if((K-A)-B>0){
        System.out.println(A*1+B*0+(((K-A)-B)*(-1)));
          return;
        }
      } if(K-A==0){
      System.out.println(A*1);
        return;
      } K-A==0 K-A K A 0 {
      System.out.println(A*1);
        return;
      } System.out.println(A*1) System.out.println System.out System System.out A*1 A 1 return; if(K-A<0){
        System.out.println(K*1);
          return;
        } K-A<0 K-A K A 0 {
        System.out.println(K*1);
          return;
        } System.out.println(K*1) System.out.println System.out System System.out K*1 K 1 return; if((K-A)-B<=0){
         System.out.println(A*1+B*0);
          return;
        } (K-A)-B<=0 (K-A)-B (K-A) K A B 0 {
         System.out.println(A*1+B*0);
          return;
        } System.out.println(A*1+B*0) System.out.println System.out System System.out A*1+B*0 A*1 A 1 B*0 B 0 return; if((K-A)-B>0){
        System.out.println(A*1+B*0+(((K-A)-B)*(-1)));
          return;
        } (K-A)-B>0 (K-A)-B (K-A) K A B 0 {
        System.out.println(A*1+B*0+(((K-A)-B)*(-1)));
          return;
        } System.out.println(A*1+B*0+(((K-A)-B)*(-1))) System.out.println System.out System System.out A*1+B*0+(((K-A)-B)*(-1)) A*1+B*0+(((K-A)-B)*(-1)) A*1 A 1 B*0 B 0 (((K-A)-B)*(-1)) ((K-A)-B) (K-A) K A B (-1) 1 return; String[] args args public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
       int A =sc.nextInt();
      int B =sc.nextInt();
      int C =sc.nextInt();
      int K =sc.nextInt();
      
      for(int i=1; i<=K; i++){
      if(K-A==0){
      System.out.println(A*1);
        return;
      }
        if(K-A<0){
        System.out.println(K*1);
          return;
        }
        if((K-A)-B<=0){
         System.out.println(A*1+B*0);
          return;
        }
        if((K-A)-B>0){
        System.out.println(A*1+B*0+(((K-A)-B)*(-1)));
          return;
        }
      }
    }
} public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
       int A =sc.nextInt();
      int B =sc.nextInt();
      int C =sc.nextInt();
      int K =sc.nextInt();
      
      for(int i=1; i<=K; i++){
      if(K-A==0){
      System.out.println(A*1);
        return;
      }
        if(K-A<0){
        System.out.println(K*1);
          return;
        }
        if((K-A)-B<=0){
         System.out.println(A*1+B*0);
          return;
        }
        if((K-A)-B>0){
        System.out.println(A*1+B*0+(((K-A)-B)*(-1)));
          return;
        }
      }
    }
} Main
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
       int A =sc.nextInt();
      int B =sc.nextInt();
      int C =sc.nextInt();
      int K =sc.nextInt();
      
      for(int i=1; i<=K; i++){
      if(K-A==0){
      System.out.println(A*1);
        return;
      }
        if(K-A<0){
        System.out.println(K*1);
          return;
        }
        if((K-A)-B<=0){
         System.out.println(A*1+B*0);
          return;
        }
        if((K-A)-B>0){
        System.out.println(A*1+B*0+(((K-A)-B)*(-1)));
          return;
        }
      }
    }
}