PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000009. Nông dân Feb và vụ khoai tây (Farmer Feb)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Nông dân Feb và vụ khoai tây (Farmer Feb)

Farmer Feb

Source: CodeChef

Version: Phuoc Hung OJ Extended

Problem Statement

Farmer Feb grows potatoes in three fields. He has harvested xx potatoes from the first and yy from the second. He has not harvested any potatoes from the third field yet. He believes his total harvest will be fortunate if its size is prime. Find the smallest positive number of potatoes he must harvest from the third field so that the total is prime. A prime is an integer greater than 11 with exactly two positive divisors.

Input

One line containing two integers xx and yy, the harvests from the first and second fields.

Output

Print the minimum positive integer zz such that x+y+zx+y+z is prime.

Subtasks

  • Subtask 1 (20 points): 1≤x≤201\le x\le 20, 1≤y≤201\le y\le 20.
  • Subtask 2 (30 points): 1≤x≤2001\le x\le 200, 1≤y≤2001\le y\le 200.
  • Subtask 3 (50 points): 1≤x≤10001\le x\le 1000, 1≤y≤10001\le y\le 1000.

Examples

Input

1 3

Output

1

Explanation

The first two fields contribute 1+3=41+3=4 potatoes. Adding z=1z=1 gives 55, which is prime. Since zz must be positive, 11 is minimal.

Input

4 3

Output

4

Explanation

The initial harvest is 77. Adding 11, 22 or 33 gives 88, 99 and 1010, all composite. Adding 44 gives prime 1111, so 44 is the minimum.