#include <bits/stdc++.h>
using namespace std;
int dp[1605][1605], mp[1005][1005];
int num[600005], x, y = 99999999;
int Euclid_GCD(int a, int b) { return b ? Euclid_GCD(b, a % b) : a; }
int main() {
  int a = 0, b, c, d, e, i, j, f;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  {
    if (a + b - c > d - 1 || c > a || c > b)
      printf("-1\n");
    else
      printf("%d\n", d - a - b + c);
  }
  return 0;
}
