#include <bits/stdc++.h>
int main(void) {
  int a, b, c, n, answer;
  scanf("%i %i %i %i", &a, &b, &c, &n);
  answer = n - a - b + c;
  if (n <= a || n <= b || n <= c || a < c || b < c || answer <= 0)
    printf("-1");
  else {
    printf("%i", answer);
  }
  return 0;
}
