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