#include <bits/stdc++.h>
using namespace std;
inline void output(long long int x) {
  if (x % 2)
    cout << x / 2 << "\n";
  else
    cout << x / 2 - 1 << "\n";
  return;
}
long long int N, K;
int main() {
  cin >> N >> K;
  if (N >= K)
    output(K);
  else {
    if ((N << 1) - 1 < K)
      cout << 0 << "\n";
    else
      output(N - (K - N) + 2);
  }
  return 0;
}
