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