#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
int main(int argc, char const *argv[]) {
  int a, b, c, n;
  cin >> a >> b >> c >> n;
  if (n >= (a + b - c + 1) && c <= a && c <= b)
    cout << n - (a + b - c) << endl;
  else
    cout << -1 << endl;
  return 0;
}
