#include <bits/stdc++.h>
using namespace std;
const long long prime = 1e9 + 7;
const long long maxN = 1e5 + 3;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long a, b, c, n;
  cin >> a >> b >> c >> n;
  if (n <= a + b - c) {
    cout << -1;
  } else if (c > a) {
    cout << -1;
  } else if (c > b) {
    cout << -1;
  } else {
    cout << n + c - a - b;
  }
  return 0;
}
