#include <bits/stdc++.h>
using namespace std;
int checkPrimeNumber(int);
long long int result[1000] = {0};
template <typename T, class C>
struct OStack : std::stack<T, C> {
  using std::stack<T, C>::c;
};
template <typename T, class C>
C& getContainer(std::stack<T, C>& s) {
  return static_cast<OStack<T, C>&>(s).c;
}
string finalstring(string s, int n) {
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) {
      reverse(s.begin(), s.begin() + i);
    }
  }
  return s;
}
int ans[6];
int main() {
  ios::sync_with_stdio(false);
  int a, b, c, n;
  cin >> a >> b >> c >> n;
  int p = n - (a + b - c);
  if (a < c || b < c || n < a || n < b || n < c) {
    cout << "-1" << endl;
    return 0;
  }
  if (p <= 0)
    cout << "-1" << endl;
  else
    cout << p << endl;
  return 0;
}
