#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j = 0, k, l, a = 0, b, m, n, ck = 0, aa, bb, dk = 0;
  cin >> n >> m >> a >> b;
  ck = (n + m) - a;
  if (n < a || m < a || ck >= b) {
    cout << "-1" << endl;
    return 0;
  } else
    cout << b - ck << endl;
}
