#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n, k;
  cin >> n >> k;
  long long int ans = 0;
  if (k <= n) {
    if (k % 2)
      ans = k / 2;
    else
      ans = k / 2 - 1;
  } else {
    if ((k - n) > (n - 1)) {
      ans = -1;
    } else {
      long long int rem = n - (k - n);
      if (rem % 2) {
        ans = rem / 2;
      } else
        ans = rem / 2 - 1;
      ans++;
    }
  }
  if (ans == -1)
    cout << 0;
  else
    cout << ans;
  cout << endl;
  return 0;
}
