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