#include <bits/stdc++.h>
using namespace std;
const long long init = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  long long ans = 0;
  if (n >= (k - 1)) {
    ans = (k - 1) / 2;
  } else {
    if (k > (2 * n - 1))
      ans = 0;
    else {
      long long temp = k - n;
      long long diff = n - temp;
      ans = (diff + 1) / 2;
    }
  }
  cout << ans << endl;
  return 0;
}
