Maximum common divisor and least common multiple

import java.util.*;
public class Main{
    public static int gcd(int a,int b)
    {
        int max=Math.max(a,b);
        int min=Math.min(a,b);
        if(max%min==0) return min;
        else return gcd(min,max%min);
    }
    public static int lcm(int a,int b)
    {
        return a*b/gcd(a,b);
    }
    public static int LCM1(int a,int b)
    {
        int lcm=b;
        while(true) {
            boolean flag=false;
            for(int i=a;i<=b;i++)
            {
                if(lcm%i!=0)
                {
                    flag=true;
                    break;
                }
            }
            if(flag) lcm++;
            else
            {
                break;
            }
        }
        return lcm;
    }
    public static void main(String args[]){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int m=n;
        while(true){
            if(LCM1(1,m)==LCM1(n+1,m))
            {
                System.out.println(m);
                break;
            }
            else m++;
        }
    }
}