#include <bits/stdc++.h>
using namespace std;
long long n, k, pas;
int main() {
  cin >> n >> k;
  if (k == 1 || n == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (n >= k - 1) {
    if (k % 2 == 0)
      cout << k / 2 - 1 << endl;
    else
      cout << (k - 1) / 2;
    return 0;
  }
  if (k - n >= n) {
    cout << 0 << endl;
    return 0;
  }
  k = 2 * n - k;
  if (k % 2 == 0)
    cout << k / 2 << endl;
  else
    cout << (k + 1) / 2 << endl;
}
