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