#include <bits/stdc++.h>
int main() {
  unsigned long long n, k;
  scanf("%I64d %I64d", &n, &k);
  const unsigned long long max_sum = n * 2ull - 1ull;
  if (k > max_sum || k == 1)
    putchar('0');
  else if (n == k) {
    if (n % 2 == 1)
      printf("%I64d", n / 2);
    else
      printf("%I64d", n / 2 - 1);
  } else if (k == max_sum)
    putchar('1');
  else if (k < n)
    printf("%I64d", (k - 1) / 2);
  else
    printf("%I64d", (2 * n - k + 1) / 2);
  return 0;
}
