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