import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int A = 1;
        int B = 0;
        int C = -1;
        int a,b,c;
        int n;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        n = sc.nextInt();
        if(a + b >= n)
        {
            System.out.println(Math.min(a,n)*A);
        }
        else
        {
            System.out.println((n-(a+b))*C+ a*A);
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        int A = 1;
        int B = 0;
        int C = -1;
        int a,b,c;
        int n;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        n = sc.nextInt();
        if(a + b >= n)
        {
            System.out.println(Math.min(a,n)*A);
        }
        else
        {
            System.out.println((n-(a+b))*C+ a*A);
        }
    }
} Main public static void main(String[] args) {
        int A = 1;
        int B = 0;
        int C = -1;
        int a,b,c;
        int n;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        n = sc.nextInt();
        if(a + b >= n)
        {
            System.out.println(Math.min(a,n)*A);
        }
        else
        {
            System.out.println((n-(a+b))*C+ a*A);
        }
    } main {
        int A = 1;
        int B = 0;
        int C = -1;
        int a,b,c;
        int n;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        n = sc.nextInt();
        if(a + b >= n)
        {
            System.out.println(Math.min(a,n)*A);
        }
        else
        {
            System.out.println((n-(a+b))*C+ a*A);
        }
    } int A = 1; A 1 int B = 0; B 0 int C = -1; C -1 1 int a a b b c; c int n; n Scanner sc = new Scanner(System.in); sc new Scanner(System.in) 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 n = sc.nextInt() n sc.nextInt() sc.nextInt sc if(a + b >= n)
        {
            System.out.println(Math.min(a,n)*A);
        }
        else
        {
            System.out.println((n-(a+b))*C+ a*A);
        } a + b >= n a + b a b n {
            System.out.println(Math.min(a,n)*A);
        } System.out.println(Math.min(a,n)*A) System.out.println System.out System System.out Math.min(a,n)*A Math.min(a,n) Math.min Math a n A {
            System.out.println((n-(a+b))*C+ a*A);
        } System.out.println((n-(a+b))*C+ a*A) System.out.println System.out System System.out (n-(a+b))*C+ a*A (n-(a+b))*C (n-(a+b)) n (a+b) a b C a*A a A String[] args args public class Main {
    public static void main(String[] args) {
        int A = 1;
        int B = 0;
        int C = -1;
        int a,b,c;
        int n;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        n = sc.nextInt();
        if(a + b >= n)
        {
            System.out.println(Math.min(a,n)*A);
        }
        else
        {
            System.out.println((n-(a+b))*C+ a*A);
        }
    }
} public class Main {
    public static void main(String[] args) {
        int A = 1;
        int B = 0;
        int C = -1;
        int a,b,c;
        int n;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        n = sc.nextInt();
        if(a + b >= n)
        {
            System.out.println(Math.min(a,n)*A);
        }
        else
        {
            System.out.println((n-(a+b))*C+ a*A);
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int A = 1;
        int B = 0;
        int C = -1;
        int a,b,c;
        int n;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        n = sc.nextInt();
        if(a + b >= n)
        {
            System.out.println(Math.min(a,n)*A);
        }
        else
        {
            System.out.println((n-(a+b))*C+ a*A);
        }
    }
}
