#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  scanf("%lld%lld", &n, &k);
  long long l = (n + 1ll) / 2, r = n;
  if (n + 1ll > k) {
    cout << (k - 1ll) / 2ll << endl;
    return 0;
  }
  if (k - n >= n) {
    cout << 0 << endl;
    return 0;
  }
  long long cnt = (n + n - k + 2ll) / 2;
  if (k % 2ll == 0 && k / 2ll <= n) cnt--;
  cout << cnt << endl;
}
