import java.util.Arrays; import java.util.Scanner; import java.util.stream.IntStream; public class Main { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); int n = stdin.nextInt(); int p = stdin.nextInt(); Main main = new Main(n, p); System.out.println(main.solve()); } private int n; private int p; private int[][] cache; public Main(int n, int p) { this.n = n; this.p = p; this.cache = new int[n + 1][n + 1]; } public int solve() { UnionFind uf = new UnionFind(n); for (int x = 0; x < n; x++) { for (int y = x + 1; y < n; y++) { if (gcd(x + 1, y + 1) != 1) { uf.union(x, y); } } } return uf.size(p - 1); } public int gcd(int x, int y) { if (cache[x][y] != 0) { return cache[x][y]; } cache[x][y] = (x < y) ? gcd(y, x) : (x % y == 0) ? y : gcd(y, x % y); return cache[x][y]; } } class UnionFind { private int[] parents; private int[] sizes; public UnionFind(int n) { parents = IntStream.range(0, n).toArray(); sizes = new int[n]; Arrays.fill(sizes, 1); } public void union(int x, int y) { x = find(x); y = find(y); if (x != y) { sizes[y] += sizes[x]; parents[x] = y; } } public int find(int x) { if (parents[x] == x) { return x; } else { parents[x] = find(parents[x]); return parents[x]; } } public int size(int x) { return sizes[find(x)]; } }