#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C, N;
  cin >> A >> B >> C >> N;
  if (A + B < C) {
    cout << -1 << endl;
    return 0;
  }
  if (A < C || B < C) {
    cout << -1 << endl;
    return 0;
  }
  int failed = N - (A + B - C);
  if (failed < 1) {
    cout << -1 << endl;
  } else
    cout << failed << endl;
  return 0;
}
