#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000010;
const long long MOD = 1000000007;
const long long LINF = 4000000000000000000;
int main() {
  long long n, k;
  cin >> n >> k;
  long long up = k / 2;
  if (k % 2 == 0) up--;
  long long lw;
  if (k > n) {
    lw = k - n;
  } else {
    lw = 1;
  }
  long long ans = up - lw + 1;
  if (2 * n < k || k < 3 || ans < 0) ans = 0;
  cout << ans << endl;
}
