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

#SP0000091. Trò chơi chọn nguyên tố (Primal Sport)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Trò chơi chọn nguyên tố (Primal Sport)

Primal Sport

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Alice and Bob make two moves starting from X0≥3X_0\ge3. Each move chooses a prime pp strictly smaller than the current integer, then replaces the integer with the smallest multiple of pp not smaller than it. Alice produces X1X_1 and Bob produces X2X_2. Given the composite integer X2X_2, find the smallest possible X0X_0 over all legal sequences.

Input

One line contains the composite integer X2X_2.

Output

Print the smallest possible starting integer X0X_0.

Subtasks

  • Subtask 1 (20 points): 4≤X2≤1004\le X_2\le 100; X2X_2 is composite.
  • Subtask 2 (30 points): 4≤X2≤100004\le X_2\le 10000; X2X_2 is composite.
  • Subtask 3 (50 points): 4≤X2≤10000004\le X_2\le 1000000; X2X_2 is composite.

Examples

Input

14

Output

6

Explanation

Start from X0=6X_0=6. Alice chooses prime 5<65<6 and rounds up to X1=10X_1=10. Bob chooses prime 7<107<10 and rounds up to X2=14X_2=14. No starting integer smaller than 66 can reach 1414 in exactly two legal moves, so the answer is 66.