#include <stdio.h>

int main() {
        int A, B, C, K;
        int sum = 0;

        scanf("%d %d %d %d", &A, &B, &C, &K);

        if(A >= K) {
                sum = K;
                goto END;
        }

        sum = A;
        K -= A;

        if(B >= K) {
                goto END;
        }

        sum -= C * K;

END:
        printf("%d\n", sum >= 0 ? sum : 0);

        return 0;
}
