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