#include <bits/stdc++.h>
using namespace std;
long long int T = 1, inf = 10000000000;
long long int legendary(long long int n) {
  long long int i, sum = 0;
  double q = 1.0 * log(n) / log(5);
  long long int v = (long long int)q;
  for (i = 1; i <= v; i += 1) {
    sum += n / pow(5, i);
  }
  return sum;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  while (T--) {
    long long int n, sz, ans = 0, u, mn, ev = 0, mx, mini, i, v, q, p, j, k, w,
                         h, l, m, x, y, od = 0, total = 0, cc = 0, pp = 0,
                         flag = 0, klag = 0, sum = 0;
    string s, s3, s1 = "Yes", s2 = "No";
    bool ok = 1;
    cin >> n >> k;
    if (k <= n)
      cout << (k - 1) / 2;
    else if (k > 2 * n - 1)
      cout << 0;
    else {
      if (n < k / 2)
        cout << 0;
      else
        cout << n - (k / 2 + 1) + 1;
    }
  }
  return 0;
}
