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