#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long n, m;
    cin >> n >> m;
    if (m > 2 * n) {
      cout << "0";
      return 0;
    }
    if (m <= n + 1) {
      cout << (m - 1) / 2;
      return 0;
    }
    long long a = m - n;
    cout << (n - a + 1) / 2;
  }
  return 0;
}
