#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  long long low = max(k - n, 1LL), high = k & 1 ? k / 2 : k / 2 - 1;
  if (high < low)
    cout << 0;
  else
    cout << (high - low + 1);
}
