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