#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long INF = 1e8;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int N = 1e3 + 10;
int main() {
  long long n, k;
  scanf("%lld%lld", &n, &k);
  long long res;
  if (k <= n + 1) {
    res = k / 2;
    if (!(k & 1)) {
      res--;
    }
  } else {
    res = max(k / 2 - (k - n) + 1, 0LL);
    if (res > 0 && !(k & 1)) {
      res--;
    }
  }
  printf("%lld\n", res);
  return 0;
}
