#include <bits/stdc++.h>
using namespace std;
int A, B, C, N;
int main() {
  scanf("%d%d%d%d", &A, &B, &C, &N);
  if (A < C || B < C || A + B >= N + C)
    puts("-1");
  else
    printf("%d\n", N - (A + B - C));
}
