/*
 * Copyright (C) 2016 Hiroyasu Kamo
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 * ACM-ICPC 2016 Japan Domestic Contest
 *  Problem C  Bamboo Blossoms
 *
 *	Author: Hiroyasu Kamo <wd@ics.nara-wu.ac.jp>
 */

#include <cstddef>
#include <cmath>
#include <algorithm>
#include <iterator>
#include <vector>
#include <iostream>
using std::max;
using std::ceil;
using std::log;
using std::vector;
using std::cin;
using std::cout;
using std::endl;

template<typename Iter, typename T, typename Int>
inline Iter
find_nth(Iter first, Iter last, const T &val, Int n)
{
	typename std::iterator_traits<Iter>::difference_type	i = 0;
	while (first != last) {
		if (*first == val) {
			if (i >= n)
				return first;
			++ i;
		}
		++ first;
	}
	return last;
}

vector<bool>
m_prime_table(int m, int size)
{
	vector<bool>	table(m, false);
	table.insert(table.end(), max(size - m, 0), true);
	for (int k = m; k * 2 < size; ++ k) {
		if (table[k]) {
			for (int i = k * 2; i < size; i += k) {
				table[i] = false;
			}
		}
	}
	return std::move(table);
}

int
dull_year(int m, int n)
{
	const double	y = m + n + 1;
	int	size = ceil(y * (log(y) + 1) * 1.25);
retry:
	const vector<bool>	table = m_prime_table(m, size);
	auto	p = find_nth(table.cbegin(), table.cend(), true, n);
	if (p == table.cend()) {
		size *= 2;
		goto retry;
	}
	return p - table.cbegin();
}

int
main()
{
	int	m, n;
	while (cin >> m >> n && m > 0 && n > 0) {
		cout << dull_year(m, n) << endl;
	}
	return 0;
}
