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