#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 {
    if (N - ((A - C) + (B - C) + C) <= 0)
      cout << "-1";
    else
      cout << N - ((A - C) + (B - C) + C);
  }
  return 0;
}
