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