#include <bits/stdc++.h>   using namespace std;   const int lim = 1e6 + 1;   int criba[lim];   void fun_criba(int n) {     for (int i = 2; i <= 2; i++) {       if (criba[i] == 0)         for (int j = i + i; j <= n; j += i) {           criba[j] = i;         }     }     for (int i = 3; i <= n; i += 2) {       if (criba[i] == 0)         for (int j = i + i; j <= n; j += i) {           criba[j] = i;         }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int x;     cin >> x;     memset(criba, 0, sizeof criba);     fun_criba(x);     int a = x;     int num = x;     for (int i = x - criba[x] + 1; i < x; i++) {       if (a >= (i - criba[i])) {         a = i - criba[i];         num = i;       }     }     x = num;     if (criba[x] != 0)       num = x - criba[x] + 1;     else       num = x - criba[x];     cout << num;     return 0;   }   