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