import java.util.Scanner;

public class Main{

    public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        int a=0;
        int b=0;
        int c=0;
        int d=0;
        int score=0;
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        d=sc.nextInt();

        if(d-a-b<=0){
            if(a>=d){
                score=d;
            }else {
                score = a*1+b*0;
            }
        }else{
            int temp=d;
            int tscore=a*1+b*0;
             temp=d-a-b;
            score=tscore+temp*-1;








        }




        System.out.print(score);



    }

} import java.util.Scanner; Scanner java.util public class Main{

    public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        int a=0;
        int b=0;
        int c=0;
        int d=0;
        int score=0;
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        d=sc.nextInt();

        if(d-a-b<=0){
            if(a>=d){
                score=d;
            }else {
                score = a*1+b*0;
            }
        }else{
            int temp=d;
            int tscore=a*1+b*0;
             temp=d-a-b;
            score=tscore+temp*-1;








        }




        System.out.print(score);



    }

} Main public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        int a=0;
        int b=0;
        int c=0;
        int d=0;
        int score=0;
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        d=sc.nextInt();

        if(d-a-b<=0){
            if(a>=d){
                score=d;
            }else {
                score = a*1+b*0;
            }
        }else{
            int temp=d;
            int tscore=a*1+b*0;
             temp=d-a-b;
            score=tscore+temp*-1;








        }




        System.out.print(score);



    } main {
        Scanner sc = new Scanner(System.in);
        int a=0;
        int b=0;
        int c=0;
        int d=0;
        int score=0;
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        d=sc.nextInt();

        if(d-a-b<=0){
            if(a>=d){
                score=d;
            }else {
                score = a*1+b*0;
            }
        }else{
            int temp=d;
            int tscore=a*1+b*0;
             temp=d-a-b;
            score=tscore+temp*-1;








        }




        System.out.print(score);



    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a=0; a 0 int b=0; b 0 int c=0; c 0 int d=0; d 0 int score=0; score 0 a=sc.nextInt() a sc.nextInt() sc.nextInt sc b=sc.nextInt() b sc.nextInt() sc.nextInt sc c=sc.nextInt() c sc.nextInt() sc.nextInt sc d=sc.nextInt() d sc.nextInt() sc.nextInt sc if(d-a-b<=0){
            if(a>=d){
                score=d;
            }else {
                score = a*1+b*0;
            }
        }else{
            int temp=d;
            int tscore=a*1+b*0;
             temp=d-a-b;
            score=tscore+temp*-1;








        } d-a-b<=0 d-a-b d-a-b d a b 0 {
            if(a>=d){
                score=d;
            }else {
                score = a*1+b*0;
            }
        } if(a>=d){
                score=d;
            }else {
                score = a*1+b*0;
            } a>=d a d {
                score=d;
            } score=d score d {
                score = a*1+b*0;
            } score = a*1+b*0 score a*1+b*0 a*1 a 1 b*0 b 0 {
            int temp=d;
            int tscore=a*1+b*0;
             temp=d-a-b;
            score=tscore+temp*-1;








        } int temp=d; temp d int tscore=a*1+b*0; tscore a*1+b*0 a*1 a 1 b*0 b 0 temp=d-a-b temp d-a-b d-a-b d a b score=tscore+temp*-1 score tscore+temp*-1 tscore temp*-1 temp -1 1 System.out.print(score) System.out.print System.out System System.out score String []args args public class Main{

    public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        int a=0;
        int b=0;
        int c=0;
        int d=0;
        int score=0;
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        d=sc.nextInt();

        if(d-a-b<=0){
            if(a>=d){
                score=d;
            }else {
                score = a*1+b*0;
            }
        }else{
            int temp=d;
            int tscore=a*1+b*0;
             temp=d-a-b;
            score=tscore+temp*-1;








        }




        System.out.print(score);



    }

} public class Main{

    public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        int a=0;
        int b=0;
        int c=0;
        int d=0;
        int score=0;
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        d=sc.nextInt();

        if(d-a-b<=0){
            if(a>=d){
                score=d;
            }else {
                score = a*1+b*0;
            }
        }else{
            int temp=d;
            int tscore=a*1+b*0;
             temp=d-a-b;
            score=tscore+temp*-1;








        }




        System.out.print(score);



    }

} Main
import java.util.Scanner;

public class Main{

    public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        int a=0;
        int b=0;
        int c=0;
        int d=0;
        int score=0;
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        d=sc.nextInt();

        if(d-a-b<=0){
            if(a>=d){
                score=d;
            }else {
                score = a*1+b*0;
            }
        }else{
            int temp=d;
            int tscore=a*1+b*0;
             temp=d-a-b;
            score=tscore+temp*-1;








        }




        System.out.print(score);



    }

}
