#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n >> k;
  if (k > 2LL * n - 1LL) {
    cout << 0;
    return 0;
  }
  if (k <= n) {
    if (k % 2 == 0) {
      cout << k / 2LL - 1LL;
      return 0;
    }
    cout << k / 2LL;
    return 0;
  }
  if (k % 2 != 0) {
    cout << n - k / 2LL;
    return 0;
  }
  cout << n - k / 2LL;
}
