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