#include <bits/stdc++.h>
using namespace std;
long long n, k, a, b, ans;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  if (k <= n) {
    a = 1;
    b = k - 1;
  } else {
    a = k - n;
    b = n;
  }
  ans = max(0ll, (b - a + 1) / 2);
  cout << ans << endl;
  return 0;
}
