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