#include <stdio.h>

int main(int argc, const char **argv)
{
    int cardp1 = 0, card0 = 0, cardm1 = 0, choice = 0, max = 0;
    int loop1 = 0, loop2 = 0;

    fscanf(stdin, "%d %d %d %d", &cardp1, &card0, &cardm1, &choice);

    for ( loop1 = 0; loop1 < cardp1; loop1++ ) max++;
    choice -= (cardp1 + card0);
    for ( loop2 = 0; loop2 < choice; loop2++ ) max--;

    fprintf(stdout, "%d\n", max);
    return 0;
}