#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int a, b, c, n;
int solve() {
  if (c > a || c > b) return -1;
  int aa = a - c, bb = b - c;
  if (aa + bb + c >= n) return -1;
  return n - aa - bb - c;
}
void run() {
  scanf("%d%d%d%d", &a, &b, &c, &n);
  printf("%d\n", solve());
}
int main() {
  run();
  return 0;
}
