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