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