#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int a, b, c, n, x, y, z;
  scanf("%lld %lld %lld %lld", &a, &b, &c, &n);
  x = a - c;
  y = b - c;
  z = c;
  if (c > a || c > b) {
    cout << "-1";
    return (0);
  }
  if (x + y + z + 1 > n) {
    cout << "-1";
    return (0);
  }
  cout << (n - x - y - z);
}
