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