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