#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, k, l, m, t, z, f, q, n, tid, a[1000100], b, x, y;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  if (k <= n + 1) {
    x = k - 1;
    x /= 2;
    cout << x;
    return 0;
  }
  x = k - n;
  y = n;
  m = (y - x + 1) / 2;
  m = max(m, 0ll);
  cout << m;
  return 0;
}
