#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long solve(long long a) {
  long long start = m - a;
  return max(0ll, (a - start + 1) / 2);
}
int main() {
  cin >> n >> m;
  if (m % 2 == 0) {
    cout << solve(min(n, m - 1));
  } else {
    cout << solve(min(n, m - 1));
  }
}
