#include <bits/stdc++.h>
using namespace std;
int pp(int n) {
  for (int i = 2; i <= floor(sqrt(n)); i++) {
    if (n % i == 0) return i;
  }
  return 1;
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  if (k > n)
    cout << max(0ll, n - k / 2) << endl;
  else
    cout << max(0ll, (k - 1) / 2) << endl;
}
int main() {
  int t = 1;
  while (t--) solve();
}
