import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    try {
      int oneNum = stdIn.nextInt();
      if (oneNum < 0) return;
      int zeroNum = stdIn.nextInt();
      if (zeroNum < 0) return;
      int minusOneNum = stdIn.nextInt();
      if (minusOneNum < 0) return;
      int selectNum = stdIn.nextInt();
      if (selectNum < 1 || (oneNum + zeroNum + minusOneNum) < selectNum || (oneNum + zeroNum + minusOneNum) > 2 * Math.pow(10, 9)) return;
      int maxValue = 0;
      int restSelect = selectNum;
      if (restSelect != 0) {
        if (oneNum <= restSelect) {
          for (int oneCnt = 0; oneCnt < oneNum; oneCnt++) {
            maxValue++;
          }
          restSelect -= oneNum;
        } else {
          for (int oneCnt = 0; oneCnt < restSelect; oneCnt++) {
            maxValue++;
          }
          restSelect = 0;
        }
      }
      if (restSelect != 0) {
        if (zeroNum <= restSelect) {
          restSelect -= zeroNum;
        } else {
          restSelect -= restSelect;
        }
      }
      if (restSelect != 0) {
        if (minusOneNum <= restSelect) {
          for (int minusOneCnt = 0; minusOneCnt < minusOneNum; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= minusOneNum;
        } else {
          for (int minusOneCnt = 0; minusOneCnt < restSelect; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= restSelect;
        }
      }
      System.out.println(maxValue);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      stdIn.close();
    }
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    try {
      int oneNum = stdIn.nextInt();
      if (oneNum < 0) return;
      int zeroNum = stdIn.nextInt();
      if (zeroNum < 0) return;
      int minusOneNum = stdIn.nextInt();
      if (minusOneNum < 0) return;
      int selectNum = stdIn.nextInt();
      if (selectNum < 1 || (oneNum + zeroNum + minusOneNum) < selectNum || (oneNum + zeroNum + minusOneNum) > 2 * Math.pow(10, 9)) return;
      int maxValue = 0;
      int restSelect = selectNum;
      if (restSelect != 0) {
        if (oneNum <= restSelect) {
          for (int oneCnt = 0; oneCnt < oneNum; oneCnt++) {
            maxValue++;
          }
          restSelect -= oneNum;
        } else {
          for (int oneCnt = 0; oneCnt < restSelect; oneCnt++) {
            maxValue++;
          }
          restSelect = 0;
        }
      }
      if (restSelect != 0) {
        if (zeroNum <= restSelect) {
          restSelect -= zeroNum;
        } else {
          restSelect -= restSelect;
        }
      }
      if (restSelect != 0) {
        if (minusOneNum <= restSelect) {
          for (int minusOneCnt = 0; minusOneCnt < minusOneNum; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= minusOneNum;
        } else {
          for (int minusOneCnt = 0; minusOneCnt < restSelect; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= restSelect;
        }
      }
      System.out.println(maxValue);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      stdIn.close();
    }
  }
} Main public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    try {
      int oneNum = stdIn.nextInt();
      if (oneNum < 0) return;
      int zeroNum = stdIn.nextInt();
      if (zeroNum < 0) return;
      int minusOneNum = stdIn.nextInt();
      if (minusOneNum < 0) return;
      int selectNum = stdIn.nextInt();
      if (selectNum < 1 || (oneNum + zeroNum + minusOneNum) < selectNum || (oneNum + zeroNum + minusOneNum) > 2 * Math.pow(10, 9)) return;
      int maxValue = 0;
      int restSelect = selectNum;
      if (restSelect != 0) {
        if (oneNum <= restSelect) {
          for (int oneCnt = 0; oneCnt < oneNum; oneCnt++) {
            maxValue++;
          }
          restSelect -= oneNum;
        } else {
          for (int oneCnt = 0; oneCnt < restSelect; oneCnt++) {
            maxValue++;
          }
          restSelect = 0;
        }
      }
      if (restSelect != 0) {
        if (zeroNum <= restSelect) {
          restSelect -= zeroNum;
        } else {
          restSelect -= restSelect;
        }
      }
      if (restSelect != 0) {
        if (minusOneNum <= restSelect) {
          for (int minusOneCnt = 0; minusOneCnt < minusOneNum; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= minusOneNum;
        } else {
          for (int minusOneCnt = 0; minusOneCnt < restSelect; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= restSelect;
        }
      }
      System.out.println(maxValue);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      stdIn.close();
    }
  } main {
    Scanner stdIn = new Scanner(System.in);
    try {
      int oneNum = stdIn.nextInt();
      if (oneNum < 0) return;
      int zeroNum = stdIn.nextInt();
      if (zeroNum < 0) return;
      int minusOneNum = stdIn.nextInt();
      if (minusOneNum < 0) return;
      int selectNum = stdIn.nextInt();
      if (selectNum < 1 || (oneNum + zeroNum + minusOneNum) < selectNum || (oneNum + zeroNum + minusOneNum) > 2 * Math.pow(10, 9)) return;
      int maxValue = 0;
      int restSelect = selectNum;
      if (restSelect != 0) {
        if (oneNum <= restSelect) {
          for (int oneCnt = 0; oneCnt < oneNum; oneCnt++) {
            maxValue++;
          }
          restSelect -= oneNum;
        } else {
          for (int oneCnt = 0; oneCnt < restSelect; oneCnt++) {
            maxValue++;
          }
          restSelect = 0;
        }
      }
      if (restSelect != 0) {
        if (zeroNum <= restSelect) {
          restSelect -= zeroNum;
        } else {
          restSelect -= restSelect;
        }
      }
      if (restSelect != 0) {
        if (minusOneNum <= restSelect) {
          for (int minusOneCnt = 0; minusOneCnt < minusOneNum; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= minusOneNum;
        } else {
          for (int minusOneCnt = 0; minusOneCnt < restSelect; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= restSelect;
        }
      }
      System.out.println(maxValue);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      stdIn.close();
    }
  } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) try {
      int oneNum = stdIn.nextInt();
      if (oneNum < 0) return;
      int zeroNum = stdIn.nextInt();
      if (zeroNum < 0) return;
      int minusOneNum = stdIn.nextInt();
      if (minusOneNum < 0) return;
      int selectNum = stdIn.nextInt();
      if (selectNum < 1 || (oneNum + zeroNum + minusOneNum) < selectNum || (oneNum + zeroNum + minusOneNum) > 2 * Math.pow(10, 9)) return;
      int maxValue = 0;
      int restSelect = selectNum;
      if (restSelect != 0) {
        if (oneNum <= restSelect) {
          for (int oneCnt = 0; oneCnt < oneNum; oneCnt++) {
            maxValue++;
          }
          restSelect -= oneNum;
        } else {
          for (int oneCnt = 0; oneCnt < restSelect; oneCnt++) {
            maxValue++;
          }
          restSelect = 0;
        }
      }
      if (restSelect != 0) {
        if (zeroNum <= restSelect) {
          restSelect -= zeroNum;
        } else {
          restSelect -= restSelect;
        }
      }
      if (restSelect != 0) {
        if (minusOneNum <= restSelect) {
          for (int minusOneCnt = 0; minusOneCnt < minusOneNum; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= minusOneNum;
        } else {
          for (int minusOneCnt = 0; minusOneCnt < restSelect; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= restSelect;
        }
      }
      System.out.println(maxValue);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      stdIn.close();
    } catch (Exception e) {
      e.printStackTrace();
    } Exception e {
      e.printStackTrace();
    } e.printStackTrace() e.printStackTrace e {
      stdIn.close();
    } stdIn.close() stdIn.close stdIn {
      int oneNum = stdIn.nextInt();
      if (oneNum < 0) return;
      int zeroNum = stdIn.nextInt();
      if (zeroNum < 0) return;
      int minusOneNum = stdIn.nextInt();
      if (minusOneNum < 0) return;
      int selectNum = stdIn.nextInt();
      if (selectNum < 1 || (oneNum + zeroNum + minusOneNum) < selectNum || (oneNum + zeroNum + minusOneNum) > 2 * Math.pow(10, 9)) return;
      int maxValue = 0;
      int restSelect = selectNum;
      if (restSelect != 0) {
        if (oneNum <= restSelect) {
          for (int oneCnt = 0; oneCnt < oneNum; oneCnt++) {
            maxValue++;
          }
          restSelect -= oneNum;
        } else {
          for (int oneCnt = 0; oneCnt < restSelect; oneCnt++) {
            maxValue++;
          }
          restSelect = 0;
        }
      }
      if (restSelect != 0) {
        if (zeroNum <= restSelect) {
          restSelect -= zeroNum;
        } else {
          restSelect -= restSelect;
        }
      }
      if (restSelect != 0) {
        if (minusOneNum <= restSelect) {
          for (int minusOneCnt = 0; minusOneCnt < minusOneNum; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= minusOneNum;
        } else {
          for (int minusOneCnt = 0; minusOneCnt < restSelect; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= restSelect;
        }
      }
      System.out.println(maxValue);
    } int oneNum = stdIn.nextInt(); oneNum stdIn.nextInt() stdIn.nextInt stdIn if (oneNum < 0) return; oneNum < 0 oneNum 0 return; int zeroNum = stdIn.nextInt(); zeroNum stdIn.nextInt() stdIn.nextInt stdIn if (zeroNum < 0) return; zeroNum < 0 zeroNum 0 return; int minusOneNum = stdIn.nextInt(); minusOneNum stdIn.nextInt() stdIn.nextInt stdIn if (minusOneNum < 0) return; minusOneNum < 0 minusOneNum 0 return; int selectNum = stdIn.nextInt(); selectNum stdIn.nextInt() stdIn.nextInt stdIn if (selectNum < 1 || (oneNum + zeroNum + minusOneNum) < selectNum || (oneNum + zeroNum + minusOneNum) > 2 * Math.pow(10, 9)) return; selectNum < 1 || (oneNum + zeroNum + minusOneNum) < selectNum || (oneNum + zeroNum + minusOneNum) > 2 * Math.pow(10, 9) selectNum < 1 || (oneNum + zeroNum + minusOneNum) < selectNum || (oneNum + zeroNum + minusOneNum) > 2 * Math.pow(10, 9) selectNum < 1 selectNum 1 (oneNum + zeroNum + minusOneNum) < selectNum (oneNum + zeroNum + minusOneNum) oneNum + zeroNum + minusOneNum oneNum zeroNum minusOneNum selectNum (oneNum + zeroNum + minusOneNum) > 2 * Math.pow(10, 9) (oneNum + zeroNum + minusOneNum) oneNum + zeroNum + minusOneNum oneNum zeroNum minusOneNum 2 * Math.pow(10, 9) 2 Math.pow(10, 9) Math.pow Math 10 9 return; int maxValue = 0; maxValue 0 int restSelect = selectNum; restSelect selectNum if (restSelect != 0) {
        if (oneNum <= restSelect) {
          for (int oneCnt = 0; oneCnt < oneNum; oneCnt++) {
            maxValue++;
          }
          restSelect -= oneNum;
        } else {
          for (int oneCnt = 0; oneCnt < restSelect; oneCnt++) {
            maxValue++;
          }
          restSelect = 0;
        }
      } restSelect != 0 restSelect 0 {
        if (oneNum <= restSelect) {
          for (int oneCnt = 0; oneCnt < oneNum; oneCnt++) {
            maxValue++;
          }
          restSelect -= oneNum;
        } else {
          for (int oneCnt = 0; oneCnt < restSelect; oneCnt++) {
            maxValue++;
          }
          restSelect = 0;
        }
      } if (oneNum <= restSelect) {
          for (int oneCnt = 0; oneCnt < oneNum; oneCnt++) {
            maxValue++;
          }
          restSelect -= oneNum;
        } else {
          for (int oneCnt = 0; oneCnt < restSelect; oneCnt++) {
            maxValue++;
          }
          restSelect = 0;
        } oneNum <= restSelect oneNum restSelect {
          for (int oneCnt = 0; oneCnt < oneNum; oneCnt++) {
            maxValue++;
          }
          restSelect -= oneNum;
        } for (int oneCnt = 0; oneCnt < oneNum; oneCnt++) {
            maxValue++;
          } int oneCnt = 0; int oneCnt = 0; oneCnt 0 oneCnt < oneNum oneCnt oneNum oneCnt++ oneCnt++ oneCnt {
            maxValue++;
          } {
            maxValue++;
          } maxValue++ maxValue restSelect -= oneNum restSelect oneNum {
          for (int oneCnt = 0; oneCnt < restSelect; oneCnt++) {
            maxValue++;
          }
          restSelect = 0;
        } for (int oneCnt = 0; oneCnt < restSelect; oneCnt++) {
            maxValue++;
          } int oneCnt = 0; int oneCnt = 0; oneCnt 0 oneCnt < restSelect oneCnt restSelect oneCnt++ oneCnt++ oneCnt {
            maxValue++;
          } {
            maxValue++;
          } maxValue++ maxValue restSelect = 0 restSelect 0 if (restSelect != 0) {
        if (zeroNum <= restSelect) {
          restSelect -= zeroNum;
        } else {
          restSelect -= restSelect;
        }
      } restSelect != 0 restSelect 0 {
        if (zeroNum <= restSelect) {
          restSelect -= zeroNum;
        } else {
          restSelect -= restSelect;
        }
      } if (zeroNum <= restSelect) {
          restSelect -= zeroNum;
        } else {
          restSelect -= restSelect;
        } zeroNum <= restSelect zeroNum restSelect {
          restSelect -= zeroNum;
        } restSelect -= zeroNum restSelect zeroNum {
          restSelect -= restSelect;
        } restSelect -= restSelect restSelect restSelect if (restSelect != 0) {
        if (minusOneNum <= restSelect) {
          for (int minusOneCnt = 0; minusOneCnt < minusOneNum; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= minusOneNum;
        } else {
          for (int minusOneCnt = 0; minusOneCnt < restSelect; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= restSelect;
        }
      } restSelect != 0 restSelect 0 {
        if (minusOneNum <= restSelect) {
          for (int minusOneCnt = 0; minusOneCnt < minusOneNum; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= minusOneNum;
        } else {
          for (int minusOneCnt = 0; minusOneCnt < restSelect; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= restSelect;
        }
      } if (minusOneNum <= restSelect) {
          for (int minusOneCnt = 0; minusOneCnt < minusOneNum; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= minusOneNum;
        } else {
          for (int minusOneCnt = 0; minusOneCnt < restSelect; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= restSelect;
        } minusOneNum <= restSelect minusOneNum restSelect {
          for (int minusOneCnt = 0; minusOneCnt < minusOneNum; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= minusOneNum;
        } for (int minusOneCnt = 0; minusOneCnt < minusOneNum; minusOneCnt++) {
            maxValue--;
          } int minusOneCnt = 0; int minusOneCnt = 0; minusOneCnt 0 minusOneCnt < minusOneNum minusOneCnt minusOneNum minusOneCnt++ minusOneCnt++ minusOneCnt {
            maxValue--;
          } {
            maxValue--;
          } maxValue-- maxValue restSelect -= minusOneNum restSelect minusOneNum {
          for (int minusOneCnt = 0; minusOneCnt < restSelect; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= restSelect;
        } for (int minusOneCnt = 0; minusOneCnt < restSelect; minusOneCnt++) {
            maxValue--;
          } int minusOneCnt = 0; int minusOneCnt = 0; minusOneCnt 0 minusOneCnt < restSelect minusOneCnt restSelect minusOneCnt++ minusOneCnt++ minusOneCnt {
            maxValue--;
          } {
            maxValue--;
          } maxValue-- maxValue restSelect -= restSelect restSelect restSelect System.out.println(maxValue) System.out.println System.out System System.out maxValue String[] args args public class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    try {
      int oneNum = stdIn.nextInt();
      if (oneNum < 0) return;
      int zeroNum = stdIn.nextInt();
      if (zeroNum < 0) return;
      int minusOneNum = stdIn.nextInt();
      if (minusOneNum < 0) return;
      int selectNum = stdIn.nextInt();
      if (selectNum < 1 || (oneNum + zeroNum + minusOneNum) < selectNum || (oneNum + zeroNum + minusOneNum) > 2 * Math.pow(10, 9)) return;
      int maxValue = 0;
      int restSelect = selectNum;
      if (restSelect != 0) {
        if (oneNum <= restSelect) {
          for (int oneCnt = 0; oneCnt < oneNum; oneCnt++) {
            maxValue++;
          }
          restSelect -= oneNum;
        } else {
          for (int oneCnt = 0; oneCnt < restSelect; oneCnt++) {
            maxValue++;
          }
          restSelect = 0;
        }
      }
      if (restSelect != 0) {
        if (zeroNum <= restSelect) {
          restSelect -= zeroNum;
        } else {
          restSelect -= restSelect;
        }
      }
      if (restSelect != 0) {
        if (minusOneNum <= restSelect) {
          for (int minusOneCnt = 0; minusOneCnt < minusOneNum; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= minusOneNum;
        } else {
          for (int minusOneCnt = 0; minusOneCnt < restSelect; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= restSelect;
        }
      }
      System.out.println(maxValue);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      stdIn.close();
    }
  }
} public class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    try {
      int oneNum = stdIn.nextInt();
      if (oneNum < 0) return;
      int zeroNum = stdIn.nextInt();
      if (zeroNum < 0) return;
      int minusOneNum = stdIn.nextInt();
      if (minusOneNum < 0) return;
      int selectNum = stdIn.nextInt();
      if (selectNum < 1 || (oneNum + zeroNum + minusOneNum) < selectNum || (oneNum + zeroNum + minusOneNum) > 2 * Math.pow(10, 9)) return;
      int maxValue = 0;
      int restSelect = selectNum;
      if (restSelect != 0) {
        if (oneNum <= restSelect) {
          for (int oneCnt = 0; oneCnt < oneNum; oneCnt++) {
            maxValue++;
          }
          restSelect -= oneNum;
        } else {
          for (int oneCnt = 0; oneCnt < restSelect; oneCnt++) {
            maxValue++;
          }
          restSelect = 0;
        }
      }
      if (restSelect != 0) {
        if (zeroNum <= restSelect) {
          restSelect -= zeroNum;
        } else {
          restSelect -= restSelect;
        }
      }
      if (restSelect != 0) {
        if (minusOneNum <= restSelect) {
          for (int minusOneCnt = 0; minusOneCnt < minusOneNum; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= minusOneNum;
        } else {
          for (int minusOneCnt = 0; minusOneCnt < restSelect; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= restSelect;
        }
      }
      System.out.println(maxValue);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      stdIn.close();
    }
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    try {
      int oneNum = stdIn.nextInt();
      if (oneNum < 0) return;
      int zeroNum = stdIn.nextInt();
      if (zeroNum < 0) return;
      int minusOneNum = stdIn.nextInt();
      if (minusOneNum < 0) return;
      int selectNum = stdIn.nextInt();
      if (selectNum < 1 || (oneNum + zeroNum + minusOneNum) < selectNum || (oneNum + zeroNum + minusOneNum) > 2 * Math.pow(10, 9)) return;
      int maxValue = 0;
      int restSelect = selectNum;
      if (restSelect != 0) {
        if (oneNum <= restSelect) {
          for (int oneCnt = 0; oneCnt < oneNum; oneCnt++) {
            maxValue++;
          }
          restSelect -= oneNum;
        } else {
          for (int oneCnt = 0; oneCnt < restSelect; oneCnt++) {
            maxValue++;
          }
          restSelect = 0;
        }
      }
      if (restSelect != 0) {
        if (zeroNum <= restSelect) {
          restSelect -= zeroNum;
        } else {
          restSelect -= restSelect;
        }
      }
      if (restSelect != 0) {
        if (minusOneNum <= restSelect) {
          for (int minusOneCnt = 0; minusOneCnt < minusOneNum; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= minusOneNum;
        } else {
          for (int minusOneCnt = 0; minusOneCnt < restSelect; minusOneCnt++) {
            maxValue--;
          }
          restSelect -= restSelect;
        }
      }
      System.out.println(maxValue);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      stdIn.close();
    }
  }
}