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. 
// package cf948;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.*;

public class CFB {
    private static final String INPUT = "959806";
//    private static final String INPUT = "994009";
//    private static final String INPUT = "8192";

    FastScanner sc;
    int[] primes;

    public static void main(String[] args) {
        new CFB().run();
    }

    public void run() {
        sc = new FastScanner(oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()));

        long s = System.currentTimeMillis();
        solve();
        System.out.flush();
        tr(System.currentTimeMillis() - s + "ms");
    }

    public void solve() {
        int x2 = sc.nextInt();

        createPrimes(x2/2);
//        if (true) return;
//      System.out.println(Arrays.toString(primes));

        int maxp2 = getMaxp(x2);
//        System.out.println(maxp2);
//        if (true) return;

        int best = x2;
        int limit = Math.min(maxp2, 239);
        for (int i = 1; i < limit; i++) {
            int x1 = x2 - maxp2 + i;
            int maxp1 = getMaxp(x1);
            if (maxp1 == 0) {
                best = Math.min(best, x1);
                continue;
            }

            best = Math.min(best, x1 - maxp1 + 1);
        }
        System.out.println(best);
    }

    private int getMaxp(int x2) {
        int maxp = 0;
//        int sqrt = (int)Math.sqrt(x2);
        for (int prime : primes) {
//            if (prime > x2) continue;
//            if (prime < sqrt) break;

            if (x2 % prime == 0) {
                return prime;
            }
        }
        return maxp/* != 0 ? maxp : x2*/;
    }

    private void createPrimes(int n) {
        Set<Integer> primes = new TreeSet<>();
        OUT: for (int i = 2; i <= n; i ++) {
            int sqrt = (int) Math.sqrt(i);
            for (int prime : primes) {
                if (prime > sqrt) break;
                if (i % prime == 0) continue OUT;
            }
            primes.add(i);
        }

        this.primes = new int[primes.size()];
        int i = primes.size();
        for (int prime: primes) {
            this.primes[--i] = prime;
        }
    }


    //********************************************************************************************
    //********************************************************************************************
    //********************************************************************************************

    private static int ceil(double d) {
        int ret = (int) d;
        return ret == d ? ret : ret + 1;
    }

    private static int round(double d) {
        return (int) (d + 0.5);
    }

    private static int gcd(int a, int b) {
        BigInteger b1 = BigInteger.valueOf(a);
        BigInteger b2 = BigInteger.valueOf(b);
        BigInteger gcd = b1.gcd(b2);
        return gcd.intValue();
    }

    private static long gcd(long a, long b) {
        BigInteger b1 = BigInteger.valueOf(a);
        BigInteger b2 = BigInteger.valueOf(b);
        BigInteger gcd = b1.gcd(b2);
        return gcd.longValue();
    }

    private int[] readIntArray(int n) {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = sc.nextInt();
        }
        return res;
    }

    private long[] readLongArray(int n) {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = sc.nextLong();
        }
        return res;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) return -1;
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

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

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

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = read();
            while (isEndline(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void tr(Object... o) {
        if (!oj) System.out.println(Arrays.deepToString(o));
    }
}