#include <iostream>
#include <cmath>
#define number 1000000
#define MAX 1000001
using namespace std;
int prime_num[MAX];
int main(void)
{
for (int i = 2; i < MAX; i++)
{
prime_num[i] = i;
}
for (int i = 2; i <= sqrt(number); i++)
{
if (prime_num[i] == 0)
continue;
for (int j = i * i; j <= number; j += i)
prime_num[j] = 0;
}
int M, N;
cin >> M >> N;
for (int i = M; i <= N; i++)
{
if (prime_num[i] != 0)
cout << prime_num[i] << '\n';
}
}
Coding/BaekJoon