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