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