Alice and Bob begin their day with a quick game. They first choose a starting number X0 ≥ 3 and try to reach one million by the process described below. 

Alice goes first and then they take alternating turns. In the i-th turn, the player whose turn it is selects a prime number smaller than the current number, and announces the smallest multiple of this prime number that is not smaller than the current number.

Formally, he or she selects a prime p < Xi - 1 and then finds the minimum Xi ≥ Xi - 1 such that p divides Xi. Note that if the selected prime p already divides Xi - 1, then the number does not change.

Eve has witnessed the state of the game after two turns. Given X2, help her determine what is the smallest possible starting number X0. Note that the players don't necessarily play optimally. You should consider all possible game evolutions.

Input

The input contains a single integer X2 (4 ≤ X2 ≤ 106). It is guaranteed that the integer X2 is composite, that is, is not prime.

Output

Output a single integer — the minimum possible X0.

Examples

Input

14


Output

6


Input

20


Output

15


Input

8192


Output

8191

Note

In the first test, the smallest possible starting number is X0 = 6. One possible course of the game is as follows: 

  * Alice picks prime 5 and announces X1 = 10
  * Bob picks prime 7 and announces X2 = 14. 



In the second case, let X0 = 15. 

  * Alice picks prime 2 and announces X1 = 16
  * Bob picks prime 5 and announces X2 = 20. 
import java.util.*;
import java.io.*;

public class Main {
    static class Reader {
        BufferedReader in;

        Reader() throws IOException {
            in = new BufferedReader(new InputStreamReader(System.in));
        }

        Reader(String name) throws IOException {
            in = new BufferedReader(new FileReader(name));
        }

        StringTokenizer tokin = new StringTokenizer("");

        String next() throws IOException {
            while (!tokin.hasMoreTokens()) {
                tokin = new StringTokenizer(in.readLine());
            }
            return tokin.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }

    static class Writer {
        PrintWriter cout;

        Writer() throws IOException {
            cout = new PrintWriter(System.out);
        }

        Writer(String name) throws IOException {
            cout = new PrintWriter(new FileWriter(name));
        }

        StringBuilder out = new StringBuilder();

        void print(Object a) {
            out.append(a);
        }

        void println(Object a) {
            out.append(a + "\n");
        }

        void close() {
            cout.print(out.toString());
            cout.close();
        }
    }

    static class pair implements Comparable {
        long a, b;

        pair(long a1, long b1) {
            a = a1;
            b = b1;
        }

        @Override
        public int compareTo(Object o) {
            pair o1 = (pair) o;
            if (a > o1.a) {
                return 1;
            } else {
                if (a < o1.a)
                    return -1;
                else
                    return 0;
            }
        }
    }

    /*static boolean isPrime(int a) {
        if (a % 2 == 0 && a != 2) {
            if (a == 2)
                return true;
            else
                return false;
        }
        int sq = (int) Math.ceil(Math.sqrt(a));
        for (int i = 3; i <= a; i++) {
            if (a % i == 0)
                return false;
        }
        return true;
    }*/

    public static void main(String args[]) throws IOException {
        Reader in = new Reader();
        Writer out = new Writer();
        int X2 = in.nextInt();
        int biggestP[] = new int[1000001];
        for (int i = 2; i < 1000000; i++) {
            if (biggestP[i] == 0) {
                for (int j = 1; j * i <= 1000000; j++) {
                    biggestP[i * j] = i;
                }
            }
        }
        int min = Integer.MAX_VALUE;
        ArrayList<Integer> X1 = new ArrayList<>(10000);
        for (int i = X2 - biggestP[X2] + 1; i <= X2; i++) {
            X1.add(i);
        }
        for (int i = 0; i < X1.size(); i++) {
            int p = biggestP[X1.get(i)];
            if (X1.get(i) != p) {
                if (min > X1.get(i) - p + 1 && X1.get(i) - p + 1 > p) {
                    min = X1.get(i) - p + 1;
                }
            }
        }
        System.out.print(min);
        out.close();
    }
}