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