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