#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) {
    cout << -1 << endl;
    return 0;
  }
  if (a < c || b < c) {
    cout << -1 << endl;
    return 0;
  }
  long long ans = a - c + b;
  if (ans >= n) {
    cout << -1 << endl;
    return 0;
  }
  cout << n - ans << endl;
}
