#include <bits/stdc++.h>
using namespace std;
long long n, k, L, R;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  long long r = n;
  long long l = 1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    long long tmp = k - mid;
    if (tmp <= mid) {
      r = mid - 1;
      continue;
    }
    if (tmp <= n) {
      L = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  if (L == 0) {
    cout << 0;
    return 0;
  }
  l = L, r = n;
  while (l <= r) {
    long long mid = (r + l) / 2;
    long long tmp = k - mid;
    if (tmp <= mid) {
      r = mid - 1;
      continue;
    }
    if (tmp <= n) {
      R = mid;
      l = mid + 1;
    } else
      l = mid - 1;
  }
  if (L == 0 || R == 0) {
    cout << 0;
    return 0;
  }
  cout << R - L + 1;
}
