#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d, n;
  cin >> a >> b >> c >> n;
  d = a - c + b - c + c;
  if ((n - d > 0) && (a >= c) && (b >= c) && (n > a) && (n > b) && (n > c))
    cout << n - d;
  else
    cout << -1;
}
