#include <bits/stdc++.h>
using namespace std;
pair<int, int> dxy[] = {make_pair(1, 0), make_pair(0, 1), make_pair(-1, 0),
                        make_pair(0, -1)};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  if (k < n + 1) {
    cout << (k - 1) / 2 << '\n';
    return 0;
  } else if (k < 2 * n) {
    long long a = n;
    long long b = k - n;
    long long answer = ((a - b) + 1) / 2;
    cout << answer << '\n';
    return 0;
  } else {
    cout << 0 << '\n';
    return 0;
  }
  return 0;
}
