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