#include <bits/stdc++.h>
using namespace std;
int main() {
  long long m, n;
  while (cin >> m >> n) {
    int flag;
    if (n & 1)
      flag = 1;
    else
      flag = 0;
    if (flag) {
      long long k = (n - 1) / 2;
      long long left, right, num;
      left = k;
      right = k + 1;
      if (2 * m - 1 < n)
        printf("0\n");
      else if (left < 1 || right > m)
        printf("0\n");
      else {
        num = min(abs(left - 1), abs(right - m));
        printf("%lld\n", num + 1);
      }
    } else {
      long long k = n / 2;
      long long left, right, num;
      left = k - 1;
      right = k + 1;
      if (2 * m - 1 < n)
        printf("0\n");
      else if (left < 1 || right > m)
        printf("0\n");
      else {
        num = min(abs(left - 1), abs(right - m));
        printf("%lld\n", num + 1);
      }
    }
  }
}
