#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long n, k, pairs, diff, t;
  cin >> n >> k;
  if (k % 2 == 0) {
    pairs = k / 2 - 1;
    t = k - 1;
    if ((t) > n) {
      diff = t - n;
      if (n < (t - (pairs - 1))) {
        cout << "0";
      } else {
        pairs = pairs - (t - n);
        cout << pairs;
      }
    } else {
      cout << pairs;
    }
  } else {
    pairs = k / 2;
    t = k - 1;
    if ((t) > n) {
      diff = t - n;
      if (n < (t - (pairs - 1))) {
        cout << "0";
      } else {
        pairs = pairs - (t - n);
        cout << pairs;
      }
    } else {
      cout << pairs;
    }
  }
}
