#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, c;
  while (cin >> a >> b >> c >> n) {
    if (c > min(a, b)) {
      cout << -1 << endl;
      continue;
    }
    int tmp = a + b - c;
    if (n > tmp) {
      cout << n - tmp << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}
