#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, c, num;
  cin >> a >> b >> c >> num;
  if (a >= c && b >= c) {
    long long int x = a + b - c;
    if (num > x) {
      cout << num - (x);
    } else
      cout << -1;
  } else
    cout << -1;
}
