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