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