#include <bits/stdc++.h>
using namespace std;
const double EPS = (1e-12);
const double PI = acos(-1);
int main() {
  ios_base::sync_with_stdio(0);
  int a, b, c, n;
  cin >> a >> b >> c >> n;
  if (a - c >= 0 && b - c >= 0 && a + b - c >= 0 && n > a + b - c) {
    cout << n - (a + b - c) << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
