#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long int a, b, c, n;
  cin >> a >> b >> c >> n;
  long long int tem = a + b - c;
  long long int temp = n - tem;
  if (a >= c && b >= c) {
    if (temp > 0)
      cout << temp << "\n";
    else
      cout << "-1\n";
  } else
    cout << "-1\n";
  return 0;
}
