#include <bits/stdc++.h>
using namespace std;
void CountTriangles(vector<int> A) {
  int n = A.size();
  sort(A.begin(), A.end());
  int count = 0;
  for (int i = n - 1; i >= 1; i--) {
    int l = 0, r = i - 1;
    while (l < r) {
      if (A[l] + A[r] > A[i]) {
        count += r - l;
        r--;
      } else
        l++;
    }
  }
  cout << "No of possible solutions: " << count;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int a, b;
  cin >> a >> b;
  if (a >= b) {
    cout << (b - 1) / 2 << endl;
  } else {
    long long int c = (2 * a - b + 1) / 2;
    cout << max(0LL, c);
  }
  return 0;
}
