#include <bits/stdc++.h>
int main() {
  long long int a, b;
  scanf("%lld %lld", &a, &b);
  long long int jawab;
  if (b >= 2 * a) {
    printf("0\n");
  } else {
    if (a >= b) {
      jawab = (b / 2);
      if (b % 2 == 0) jawab--;
    } else {
      long long int min = b - a;
      jawab = (b / 2) - min + 1;
      if (b % 2 == 0) jawab--;
    }
    printf("%lld\n", jawab);
  }
  return 0;
}
