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