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