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