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