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