#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b;
  scanf("%lld%lld", &a, &b);
  long long s = max(1ll, b - a), e = min(a, b - 1ll);
  if (b - s == s) s++;
  if (b - e == e) e--;
  long long ans = max(0ll, (e - s + 1) / 2);
  printf("%lld\n", max(0ll, (e - s + 1) / 2));
  return 0;
}
