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