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