#include <bits/stdc++.h>
using namespace std;
long long int _ceil(long long int A, long long int B) {
  if (A % B == 0)
    return A / B;
  else
    return (A / B) + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int Tests = 1;
  while (Tests--) {
    long long int N, K;
    cin >> N >> K;
    long long int pairs = (K - 1) / 2;
    long long int diff = K - N - 1;
    if (diff >= 0) {
      long long int zero = 0;
      cout << max(zero, (pairs - diff)) << "\n";
    } else
      cout << pairs << "\n";
  }
}
