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