#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int l = 1, h, i, n, x, t, q, y = -1, z = 0, a = 0, b = 0, c = 0, k,
                sum = 0, m, d = 0, r, w, j, ans, s, mini = INT_MAX,
                maxi = INT_MIN;
  bool cou;
  float kl;
  long long int count = 0;
  t = 1;
  vector<bool> sie(1000001, 0);
  char cg;
  string str, std;
  a = 1;
  while (t--) {
    cin >> a >> b >> c >> n;
    if (a < c || b < c) {
      cout << -1;
    } else {
      a -= c;
      b -= c;
      x = a + b + c;
      if (n <= x)
        cout << -1;
      else
        cout << n - x;
    }
  }
}
