import java.util.*;
public class Main { 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long o=0;
        long x=sc.nextLong();
        long y=sc.nextLong();
      	long z=sc.nextLong();
        long a=sc.nextLong();
      	if(a>x){
        	o+=x;  
          	a-=x;
          	a-=y;
          if(a>0){
          	o-=a;
          }
        }else{
          o=a;
        	      	
        }
        
      System.out.println(o);
    }
}   import java.util.*; util.* java public class Main { 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long o=0;
        long x=sc.nextLong();
        long y=sc.nextLong();
      	long z=sc.nextLong();
        long a=sc.nextLong();
      	if(a>x){
        	o+=x;  
          	a-=x;
          	a-=y;
          if(a>0){
          	o-=a;
          }
        }else{
          o=a;
        	      	
        }
        
      System.out.println(o);
    }
} Main public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long o=0;
        long x=sc.nextLong();
        long y=sc.nextLong();
      	long z=sc.nextLong();
        long a=sc.nextLong();
      	if(a>x){
        	o+=x;  
          	a-=x;
          	a-=y;
          if(a>0){
          	o-=a;
          }
        }else{
          o=a;
        	      	
        }
        
      System.out.println(o);
    } main {
        Scanner sc=new Scanner(System.in);
        long o=0;
        long x=sc.nextLong();
        long y=sc.nextLong();
      	long z=sc.nextLong();
        long a=sc.nextLong();
      	if(a>x){
        	o+=x;  
          	a-=x;
          	a-=y;
          if(a>0){
          	o-=a;
          }
        }else{
          o=a;
        	      	
        }
        
      System.out.println(o);
    } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) long o=0; o 0 long x=sc.nextLong(); x sc.nextLong() sc.nextLong sc long y=sc.nextLong(); y sc.nextLong() sc.nextLong sc long z=sc.nextLong(); z sc.nextLong() sc.nextLong sc long a=sc.nextLong(); a sc.nextLong() sc.nextLong sc if(a>x){
        	o+=x;  
          	a-=x;
          	a-=y;
          if(a>0){
          	o-=a;
          }
        }else{
          o=a;
        	      	
        } a>x a x {
        	o+=x;  
          	a-=x;
          	a-=y;
          if(a>0){
          	o-=a;
          }
        } o+=x o x a-=x a x a-=y a y if(a>0){
          	o-=a;
          } a>0 a 0 {
          	o-=a;
          } o-=a o a {
          o=a;
        	      	
        } o=a o a System.out.println(o) System.out.println System.out System System.out o String[] args args public class Main { 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long o=0;
        long x=sc.nextLong();
        long y=sc.nextLong();
      	long z=sc.nextLong();
        long a=sc.nextLong();
      	if(a>x){
        	o+=x;  
          	a-=x;
          	a-=y;
          if(a>0){
          	o-=a;
          }
        }else{
          o=a;
        	      	
        }
        
      System.out.println(o);
    }
} public class Main { 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long o=0;
        long x=sc.nextLong();
        long y=sc.nextLong();
      	long z=sc.nextLong();
        long a=sc.nextLong();
      	if(a>x){
        	o+=x;  
          	a-=x;
          	a-=y;
          if(a>0){
          	o-=a;
          }
        }else{
          o=a;
        	      	
        }
        
      System.out.println(o);
    }
} Main
import java.util.*;
public class Main { 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long o=0;
        long x=sc.nextLong();
        long y=sc.nextLong();
      	long z=sc.nextLong();
        long a=sc.nextLong();
      	if(a>x){
        	o+=x;  
          	a-=x;
          	a-=y;
          if(a>0){
          	o-=a;
          }
        }else{
          o=a;
        	      	
        }
        
      System.out.println(o);
    }
}  