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