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