#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int s, a, b, c, d, m, n, k, l, i, j, p, q, s1 = 1, s2 = 0;
  cin >> n >> k;
  if (n + n - 1 < k)
    cout << 0;
  else if (k > n) {
    cout << (n - (k - n) + 1) / 2;
  } else {
    cout << (k - 1) / 2;
  }
  return 0;
}
