#include <bits/stdc++.h>
using namespace std;
const int mod1 = 1e9 + 7;
const int mod2 = 1e9 + 9;
const int maxN = 2e5 + 7;
const int INF = 1e9 + 7;
using namespace std;
long long l, r, n, k, mid, ans, bl;
int main() {
  cin >> n >> k;
  if (k <= n) {
    cout << max(0ll, (k - 1) / 2);
    exit(0);
  }
  if (n + (n - 1) < k) {
    cout << 0;
    exit(0);
  } else {
    ans = k - n;
    cout << (n - ans + 1) / 2;
  }
}
