#include <bits/stdc++.h>
using namespace std;
int a[100001];
int main(void) {
  int a, b, c, n, ans;
  scanf("%d%d%d%d", &a, &b, &c, &n);
  if (c > a || c > b)
    ans = -1;
  else {
    ans = n - (a + b - c);
    if (ans < 1) ans = -1;
  }
  printf("%d", ans);
}
