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