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