import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    String column[] = line.split(" ");
    int card1 = Integer.parseInt(column[0]);
    int card0 = Integer.parseInt(column[1]);
    int draw = Integer.parseInt(column[3]);
    
    if(card1 >= draw){
      System.out.println(draw);
    }else if(card1 + card0 >= draw){
      System.out.println(card1);
    }else{
      System.out.println(card1 - (draw - card1 -card0));
    }
  }
} import java.util.Scanner; Scanner java.util public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    String column[] = line.split(" ");
    int card1 = Integer.parseInt(column[0]);
    int card0 = Integer.parseInt(column[1]);
    int draw = Integer.parseInt(column[3]);
    
    if(card1 >= draw){
      System.out.println(draw);
    }else if(card1 + card0 >= draw){
      System.out.println(card1);
    }else{
      System.out.println(card1 - (draw - card1 -card0));
    }
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    String column[] = line.split(" ");
    int card1 = Integer.parseInt(column[0]);
    int card0 = Integer.parseInt(column[1]);
    int draw = Integer.parseInt(column[3]);
    
    if(card1 >= draw){
      System.out.println(draw);
    }else if(card1 + card0 >= draw){
      System.out.println(card1);
    }else{
      System.out.println(card1 - (draw - card1 -card0));
    }
  } main {
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    String column[] = line.split(" ");
    int card1 = Integer.parseInt(column[0]);
    int card0 = Integer.parseInt(column[1]);
    int draw = Integer.parseInt(column[3]);
    
    if(card1 >= draw){
      System.out.println(draw);
    }else if(card1 + card0 >= draw){
      System.out.println(card1);
    }else{
      System.out.println(card1 - (draw - card1 -card0));
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc String column[] = line.split(" "); column line.split(" ") line.split line " " int card1 = Integer.parseInt(column[0]); card1 Integer.parseInt(column[0]) Integer.parseInt Integer column[0] column 0 int card0 = Integer.parseInt(column[1]); card0 Integer.parseInt(column[1]) Integer.parseInt Integer column[1] column 1 int draw = Integer.parseInt(column[3]); draw Integer.parseInt(column[3]) Integer.parseInt Integer column[3] column 3 if(card1 >= draw){
      System.out.println(draw);
    }else if(card1 + card0 >= draw){
      System.out.println(card1);
    }else{
      System.out.println(card1 - (draw - card1 -card0));
    } card1 >= draw card1 draw {
      System.out.println(draw);
    } System.out.println(draw) System.out.println System.out System System.out draw if(card1 + card0 >= draw){
      System.out.println(card1);
    }else{
      System.out.println(card1 - (draw - card1 -card0));
    } card1 + card0 >= draw card1 + card0 card1 card0 draw {
      System.out.println(card1);
    } System.out.println(card1) System.out.println System.out System System.out card1 {
      System.out.println(card1 - (draw - card1 -card0));
    } System.out.println(card1 - (draw - card1 -card0)) System.out.println System.out System System.out card1 - (draw - card1 -card0) card1 (draw - card1 -card0) draw - card1 -card0 draw card1 card0 String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    String column[] = line.split(" ");
    int card1 = Integer.parseInt(column[0]);
    int card0 = Integer.parseInt(column[1]);
    int draw = Integer.parseInt(column[3]);
    
    if(card1 >= draw){
      System.out.println(draw);
    }else if(card1 + card0 >= draw){
      System.out.println(card1);
    }else{
      System.out.println(card1 - (draw - card1 -card0));
    }
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    String column[] = line.split(" ");
    int card1 = Integer.parseInt(column[0]);
    int card0 = Integer.parseInt(column[1]);
    int draw = Integer.parseInt(column[3]);
    
    if(card1 >= draw){
      System.out.println(draw);
    }else if(card1 + card0 >= draw){
      System.out.println(card1);
    }else{
      System.out.println(card1 - (draw - card1 -card0));
    }
  }
} Main
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    String column[] = line.split(" ");
    int card1 = Integer.parseInt(column[0]);
    int card0 = Integer.parseInt(column[1]);
    int draw = Integer.parseInt(column[3]);
    
    if(card1 >= draw){
      System.out.println(draw);
    }else if(card1 + card0 >= draw){
      System.out.println(card1);
    }else{
      System.out.println(card1 - (draw - card1 -card0));
    }
  }
}
