#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, x, y;
  cin >> n >> k;
  if ((2 * n - 1) < k || n == 1 || k == 1)
    cout << "0";
  else {
    for (x = n, y = 1; x > 0; x--, y++) {
      if ((k - x) <= n && (k - x) > 0) {
        x = k - x;
        cout << ((k - (2 * x) + 1) / 2);
        return 0;
      }
      if (k - y <= n && (k - y) > 0) {
        cout << ((k - (2 * y) + 1) / 2);
        return 0;
      }
    }
    cout << "0";
  }
}
