#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 4;
inline void out(long long x) {
  if (x > 9) out(x / 10);
  putchar(x % 10 + '0');
}
void read(long long &x) {
  char ch;
  bool flag = 0;
  for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1);
       ch = getchar())
    ;
  for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar())
    ;
  x *= 1 - 2 * flag;
}
int main() {
  long long n, m;
  read(n), read(m);
  if (m == 1 || m == 2) return 0 * printf("0\n");
  if (n >= m) {
    if (m % 2) {
      printf("%lld\n", m / 2);
    } else
      printf("%lld\n", (m - 1) / 2);
    return 0;
  }
  if (m / 2 <= n) {
    if (m / 2 > n - m / 2) {
      printf("%lld\n", n - m / 2);
    } else {
      printf("%lld\n", m / 2);
    }
    return 0;
  }
  puts("0");
  return 0;
}
