import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N, P = map(int, read().split()) U = N + 1 is_prime = np.zeros(U, np.bool_) is_prime[2] = 1 is_prime[3::2] = 1 for p in range(3, U, 2): if p * p >= U: break if is_prime[p]: is_prime[p*p::p+p] = 0 M = N // 2 + 1 n_single = np.count_nonzero(is_prime[M:]) + 1 if P == 1 or (P >= M and is_prime[P]): answer = 1 else: answer = N - n_single print(answer)