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