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