#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, n;
  cin >> a >> b >> c >> n;
  b -= c;
  if (b >= 0)
    n -= (a + b);
  else {
    cout << -1 << endl;
    return 0;
  }
  if (c > a) {
    cout << -1 << endl;
    return 0;
  }
  if (n > 0) {
    cout << n << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
