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