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