#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int MaxN = 1e5 + 5;
const int MaxM = 1e5 + 5;
const int mod = 1e9 + 7;
const double PI = acos(-1.0);
const double eps = 1e-8;
inline long long read() {
  long long x = 0, flag = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return flag * x;
}
long long N, K;
int main() {
  while (~scanf("%lld%lld", &N, &K)) {
    if (2 * N - 1 < K)
      printf("0\n");
    else {
      if (K <= N + 1)
        printf("%lld\n", (K - 1) / 2);
      else {
        long long lose = K - N;
        if (K & 1)
          printf("%lld\n", K / 2 - lose + 1);
        else
          printf("%lld\n", K / 2 - lose);
      }
    }
  }
}
