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