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