#include <bits/stdc++.h>
long long n, k;
int main() {
  scanf("%I64d%I64d", &n, &k);
  register long long l = 0, r = k >> 1;
  if (r >= n) return 0 * puts("0");
  if (n + 1 < k) l = k - n - 1;
  printf("%I64d\n", r - l - (~k & 1));
  return 0;
}
