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