#include<stdio.h>

int main(){

  int i;
  int one, zero, minus_one;
  int select;
  int result = 0;

  scanf("%d %d %d %d", &one, &zero, &minus_one, &select);

  for(i = 0; i < select; i++){
    if(i < one){
      result += 1;
      continue;
    }
    else if(i < one + zero){
      continue;
    }
    else{
      result -= 1;
    }
  }
  printf("%d", result);
}