#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const int INF = numeric_limits<int>::max();
const long long LINF = numeric_limits<long long>::max();
const long long mod = 1000 * 1000 * 1000 + 7;
void solve() {
  long long n, k;
  cin >> n >> k;
  if ((k <= 2) || (k >= 2 * n)) {
    cout << 0 << endl;
    return;
  }
  if (k <= n + 1) {
    cout << (k - 1) / 2 << endl;
  } else {
    cout << (2 * n + 1 - k) / 2 << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  solve();
  return 0;
}
