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