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