#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, s = 0, a;
  cin >> n >> m;
  if (m >= 2 * n) {
    cout << 0;
    return 0;
  }
  if (m <= n) {
    cout << (long long int)((m - 1) / 2);
  } else {
    cout << (long long int)((2 * n + 1 - m) / 2);
  }
}
