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