#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, n, t, k = 0, cnt = 0, mini = LLONG_MAX, maxi = LLONG_MIN,
                        ans = 0;
  long long m;
  cin >> n >> k;
  if (k > 2 * n + 1) return cout << 0, 0;
  if (n >= k) return cout << (k - 1) / 2, 0;
  cnt = 2 * n - k + 1;
  return cout << cnt / 2, 0;
  return 0;
}
