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