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