#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long oo = 1e18;
const long long mod = 1e9 + 7;
long long freq[26][N + 1];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  long long n, k;
  cin >> n >> k;
  if ((n - 1 + n) < k || k == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (k <= n) {
    cout << (k - 1) / 2 << endl;
    return 0;
  }
  long long all = (k - 1) / 2;
  long long tobeRemoved = k - n - 1;
  cout << all - tobeRemoved << endl;
  return 0;
}
