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