#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int maxm = 4000 + 10;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const double eps = 1e-7;
long long n, k;
int main() {
  cin >> n >> k;
  if (n + (n - 1) < k) {
    cout << 0 << endl;
    return 0;
  }
  long long l, r;
  if (n + 1 < k) {
    l = k - n;
    r = n;
  } else {
    l = 1;
    r = k - 1;
  }
  cout << (r - l + 1) / 2 << endl;
  return 0;
}
