#include <bits/stdc++.h>
using namespace std;
bool isPrime[18409202];
int main() {
  long long a, b, c, n, a1, b1, c1;
  cin >> a >> b >> c >> n;
  a1 = abs(a - c);
  b1 = abs(b - c);
  c1 = a1 + b1 + c;
  if (a == 0 && b == 0 && c * 2 < n) {
    cout << (n - c * 2) << endl;
    return 0;
  }
  if (c1 < n && (n - c1) > 0 && a >= c && b >= c)
    cout << (n - c1) << endl;
  else
    cout << -1 << endl;
}
