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