import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long one = sc.nextLong();
    long zero = sc.nextLong();
    long minus = sc.nextLong();
    long card = sc.nextLong();
    long sum = 0;
    if(card <= one){
      System.out.println(card);
    }
    else{
      sum += one;
      card -= one;
      if(card > zero){
        card -= zero;
        for(int i = 0;i < card;i++){
          sum--;
        }
      }
      System.out.println(sum);
    }
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long one = sc.nextLong();
    long zero = sc.nextLong();
    long minus = sc.nextLong();
    long card = sc.nextLong();
    long sum = 0;
    if(card <= one){
      System.out.println(card);
    }
    else{
      sum += one;
      card -= one;
      if(card > zero){
        card -= zero;
        for(int i = 0;i < card;i++){
          sum--;
        }
      }
      System.out.println(sum);
    }
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long one = sc.nextLong();
    long zero = sc.nextLong();
    long minus = sc.nextLong();
    long card = sc.nextLong();
    long sum = 0;
    if(card <= one){
      System.out.println(card);
    }
    else{
      sum += one;
      card -= one;
      if(card > zero){
        card -= zero;
        for(int i = 0;i < card;i++){
          sum--;
        }
      }
      System.out.println(sum);
    }
  } main {
    Scanner sc = new Scanner(System.in);
    long one = sc.nextLong();
    long zero = sc.nextLong();
    long minus = sc.nextLong();
    long card = sc.nextLong();
    long sum = 0;
    if(card <= one){
      System.out.println(card);
    }
    else{
      sum += one;
      card -= one;
      if(card > zero){
        card -= zero;
        for(int i = 0;i < card;i++){
          sum--;
        }
      }
      System.out.println(sum);
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long one = sc.nextLong(); one sc.nextLong() sc.nextLong sc long zero = sc.nextLong(); zero sc.nextLong() sc.nextLong sc long minus = sc.nextLong(); minus sc.nextLong() sc.nextLong sc long card = sc.nextLong(); card sc.nextLong() sc.nextLong sc long sum = 0; sum 0 if(card <= one){
      System.out.println(card);
    }
    else{
      sum += one;
      card -= one;
      if(card > zero){
        card -= zero;
        for(int i = 0;i < card;i++){
          sum--;
        }
      }
      System.out.println(sum);
    } card <= one card one {
      System.out.println(card);
    } System.out.println(card) System.out.println System.out System System.out card {
      sum += one;
      card -= one;
      if(card > zero){
        card -= zero;
        for(int i = 0;i < card;i++){
          sum--;
        }
      }
      System.out.println(sum);
    } sum += one sum one card -= one card one if(card > zero){
        card -= zero;
        for(int i = 0;i < card;i++){
          sum--;
        }
      } card > zero card zero {
        card -= zero;
        for(int i = 0;i < card;i++){
          sum--;
        }
      } card -= zero card zero for(int i = 0;i < card;i++){
          sum--;
        } int i = 0; int i = 0; i 0 i < card i card i++ i++ i {
          sum--;
        } {
          sum--;
        } sum-- sum System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long one = sc.nextLong();
    long zero = sc.nextLong();
    long minus = sc.nextLong();
    long card = sc.nextLong();
    long sum = 0;
    if(card <= one){
      System.out.println(card);
    }
    else{
      sum += one;
      card -= one;
      if(card > zero){
        card -= zero;
        for(int i = 0;i < card;i++){
          sum--;
        }
      }
      System.out.println(sum);
    }
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long one = sc.nextLong();
    long zero = sc.nextLong();
    long minus = sc.nextLong();
    long card = sc.nextLong();
    long sum = 0;
    if(card <= one){
      System.out.println(card);
    }
    else{
      sum += one;
      card -= one;
      if(card > zero){
        card -= zero;
        for(int i = 0;i < card;i++){
          sum--;
        }
      }
      System.out.println(sum);
    }
  }
} Main
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long one = sc.nextLong();
    long zero = sc.nextLong();
    long minus = sc.nextLong();
    long card = sc.nextLong();
    long sum = 0;
    if(card <= one){
      System.out.println(card);
    }
    else{
      sum += one;
      card -= one;
      if(card > zero){
        card -= zero;
        for(int i = 0;i < card;i++){
          sum--;
        }
      }
      System.out.println(sum);
    }
  }
}