#include <bits/stdc++.h>
template <typename Arg1>
void ZZ(const char* name, Arg1&& arg1) {
  std::cout << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cout.write(names, comma - names) << " = " << arg1;
  ZZ(comma, args...);
}
using namespace std;
long long n, m, k, q;
vector<long long> ar;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  if (n == 1) {
    cout << 0 << endl;
  } else if (n >= k) {
    cout << (k / 2 - (k % 2 == 0)) << endl;
  } else if (n <= k / 2) {
    cout << 0 << endl;
  } else {
    cout << (n - k / 2) << endl;
  }
  return 0;
}
