#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, t1, t2, res;
  cin >> n >> k;
  t1 = min((long long)ceil(k / 2.0), n) - 1LL;
  t2 = n - max(1LL, k / 2);
  res = min(t1, t2);
  if (res < 0)
    cout << "0\n";
  else
    cout << res << endl;
  return 0;
}
