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