import java.util.Scanner;

public class Main {
    public static void main(final String[] args) throws Exception {
        final Scanner scan = new Scanner(System.in);
        int plusCount = scan.nextInt();
        int zeroCount = scan.nextInt();
        int minusCount = scan.nextInt();
        int getCount = scan.nextInt();
        scan.close();
        int score = 0;

        if (getCount - plusCount <= 0) {
            score = getCount;
        } else {
            getCount -= plusCount;
            score += plusCount;
            if (getCount - zeroCount <= 0) {
            } else {
                getCount -= zeroCount;
                if (getCount - minusCount <= 0) {
                  score -= getCount;
                } else {
                    score -= minusCount;
                }
            }
        }

        System.out.println(score);

        
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(final String[] args) throws Exception {
        final Scanner scan = new Scanner(System.in);
        int plusCount = scan.nextInt();
        int zeroCount = scan.nextInt();
        int minusCount = scan.nextInt();
        int getCount = scan.nextInt();
        scan.close();
        int score = 0;

        if (getCount - plusCount <= 0) {
            score = getCount;
        } else {
            getCount -= plusCount;
            score += plusCount;
            if (getCount - zeroCount <= 0) {
            } else {
                getCount -= zeroCount;
                if (getCount - minusCount <= 0) {
                  score -= getCount;
                } else {
                    score -= minusCount;
                }
            }
        }

        System.out.println(score);

        
    }
} Main public static void main(final String[] args) throws Exception {
        final Scanner scan = new Scanner(System.in);
        int plusCount = scan.nextInt();
        int zeroCount = scan.nextInt();
        int minusCount = scan.nextInt();
        int getCount = scan.nextInt();
        scan.close();
        int score = 0;

        if (getCount - plusCount <= 0) {
            score = getCount;
        } else {
            getCount -= plusCount;
            score += plusCount;
            if (getCount - zeroCount <= 0) {
            } else {
                getCount -= zeroCount;
                if (getCount - minusCount <= 0) {
                  score -= getCount;
                } else {
                    score -= minusCount;
                }
            }
        }

        System.out.println(score);

        
    } main {
        final Scanner scan = new Scanner(System.in);
        int plusCount = scan.nextInt();
        int zeroCount = scan.nextInt();
        int minusCount = scan.nextInt();
        int getCount = scan.nextInt();
        scan.close();
        int score = 0;

        if (getCount - plusCount <= 0) {
            score = getCount;
        } else {
            getCount -= plusCount;
            score += plusCount;
            if (getCount - zeroCount <= 0) {
            } else {
                getCount -= zeroCount;
                if (getCount - minusCount <= 0) {
                  score -= getCount;
                } else {
                    score -= minusCount;
                }
            }
        }

        System.out.println(score);

        
    } final Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int plusCount = scan.nextInt(); plusCount scan.nextInt() scan.nextInt scan int zeroCount = scan.nextInt(); zeroCount scan.nextInt() scan.nextInt scan int minusCount = scan.nextInt(); minusCount scan.nextInt() scan.nextInt scan int getCount = scan.nextInt(); getCount scan.nextInt() scan.nextInt scan scan.close() scan.close scan int score = 0; score 0 if (getCount - plusCount <= 0) {
            score = getCount;
        } else {
            getCount -= plusCount;
            score += plusCount;
            if (getCount - zeroCount <= 0) {
            } else {
                getCount -= zeroCount;
                if (getCount - minusCount <= 0) {
                  score -= getCount;
                } else {
                    score -= minusCount;
                }
            }
        } getCount - plusCount <= 0 getCount - plusCount getCount plusCount 0 {
            score = getCount;
        } score = getCount score getCount {
            getCount -= plusCount;
            score += plusCount;
            if (getCount - zeroCount <= 0) {
            } else {
                getCount -= zeroCount;
                if (getCount - minusCount <= 0) {
                  score -= getCount;
                } else {
                    score -= minusCount;
                }
            }
        } getCount -= plusCount getCount plusCount score += plusCount score plusCount if (getCount - zeroCount <= 0) {
            } else {
                getCount -= zeroCount;
                if (getCount - minusCount <= 0) {
                  score -= getCount;
                } else {
                    score -= minusCount;
                }
            } getCount - zeroCount <= 0 getCount - zeroCount getCount zeroCount 0 {
            } {
                getCount -= zeroCount;
                if (getCount - minusCount <= 0) {
                  score -= getCount;
                } else {
                    score -= minusCount;
                }
            } getCount -= zeroCount getCount zeroCount if (getCount - minusCount <= 0) {
                  score -= getCount;
                } else {
                    score -= minusCount;
                } getCount - minusCount <= 0 getCount - minusCount getCount minusCount 0 {
                  score -= getCount;
                } score -= getCount score getCount {
                    score -= minusCount;
                } score -= minusCount score minusCount System.out.println(score) System.out.println System.out System System.out score final String[] args args public class Main {
    public static void main(final String[] args) throws Exception {
        final Scanner scan = new Scanner(System.in);
        int plusCount = scan.nextInt();
        int zeroCount = scan.nextInt();
        int minusCount = scan.nextInt();
        int getCount = scan.nextInt();
        scan.close();
        int score = 0;

        if (getCount - plusCount <= 0) {
            score = getCount;
        } else {
            getCount -= plusCount;
            score += plusCount;
            if (getCount - zeroCount <= 0) {
            } else {
                getCount -= zeroCount;
                if (getCount - minusCount <= 0) {
                  score -= getCount;
                } else {
                    score -= minusCount;
                }
            }
        }

        System.out.println(score);

        
    }
} public class Main {
    public static void main(final String[] args) throws Exception {
        final Scanner scan = new Scanner(System.in);
        int plusCount = scan.nextInt();
        int zeroCount = scan.nextInt();
        int minusCount = scan.nextInt();
        int getCount = scan.nextInt();
        scan.close();
        int score = 0;

        if (getCount - plusCount <= 0) {
            score = getCount;
        } else {
            getCount -= plusCount;
            score += plusCount;
            if (getCount - zeroCount <= 0) {
            } else {
                getCount -= zeroCount;
                if (getCount - minusCount <= 0) {
                  score -= getCount;
                } else {
                    score -= minusCount;
                }
            }
        }

        System.out.println(score);

        
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) throws Exception {
        final Scanner scan = new Scanner(System.in);
        int plusCount = scan.nextInt();
        int zeroCount = scan.nextInt();
        int minusCount = scan.nextInt();
        int getCount = scan.nextInt();
        scan.close();
        int score = 0;

        if (getCount - plusCount <= 0) {
            score = getCount;
        } else {
            getCount -= plusCount;
            score += plusCount;
            if (getCount - zeroCount <= 0) {
            } else {
                getCount -= zeroCount;
                if (getCount - minusCount <= 0) {
                  score -= getCount;
                } else {
                    score -= minusCount;
                }
            }
        }

        System.out.println(score);

        
    }
}
