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