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