#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  if (k > 2 * n - 1 or n == 1 or (k < 3 and n >= 2)) {
    cout << "0\n";
    return 0;
  }
  long long int l, r;
  if (k > n) {
    r = n;
    l = k - n;
  } else {
    l = 1;
    r = k - 1;
  }
  long long int ans = (r - l) / 2;
  if (r % 2 != l % 2) ans++;
  cout << ans << endl;
  return 0;
}
