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