#include <bits/stdc++.h>
using namespace std;
void solve() {
  unsigned long long n, k;
  cin >> n >> k;
  if (n + n - 1 < k || k < 3) {
    cout << 0 << " ";
    return;
  }
  unsigned long long c = 0;
  if (k > n) {
    long long l = k - n;
    c = (n - l + 1) / 2;
  } else if (k < n) {
    c = (k - 1) / 2;
  } else {
    c = (n - 1) / 2;
  }
  cout << c << " ";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
