#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int INF = (int)(1e9 + 1e6);
const long long LINF = (long long)(4e18);
const double EPS = 1e-14;
const long long mod = 1e9 + 7;
mt19937 ggen;
void solve();
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(0);
  ggen = mt19937(1337);
  solve();
}
long long gcd(long long a, long long b);
long long lcm(long long a, long long b);
void solve() {
  int a, b, c, n;
  cin >> a >> b >> c >> n;
  a -= c;
  b -= c;
  if (a < 0 || b < 0) {
    cout << -1;
    return;
  }
  n -= a;
  n -= b;
  n -= c;
  if (n < 1) {
    cout << -1;
    return;
  }
  cout << n;
  return;
}
