#include <stdio.h>

int main(){

  long int A = 0, B = 0, C = 0, K = 0;

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

  if( K > A ){
    K = K - A;
  }
  else{
    printf("%ld \n", K);
    K = 0;
  }

  if( K != 0 ){
    if( K > B ){
      K = K - B;
      A = A - K;
      printf("%ld \n", A);
    }
    else{
      printf("%ld \n", A);
    }
  }

  return 0;
}