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