#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  long long n, k, x, y;
  cin >> n >> k;
  x = min(n, (k + 1) / 2 - 1);
  y = max(1LL, k - n);
  cout << max(0LL, x - y + 1LL) << "\n";
  return 0;
}
