#!/usr/bin/env python3 def is_prime(n): if n == 1: return False for i in range(2, int(n**0.5)+1): if n % i == 0: return False return True def bfs(n, w, initial, accept, deny=None): que = [initial] i = 0 pushed = set(que) while i < len(que): if accept(que, i): return True if deny is not None and deny(que, i): return False x = que[i] i += 1 def f(y): if y not in pushed and not is_prime(y): que.append(y) pushed.add(y) if x-1 > 0 and x % w != 1: f(x-1) if x+1 <= n and x % w != 0: f(x+1) if x-w > 0: f(x-w) if x+w <= n: f(x+w) def solve(n): if n < 300: for w in range(1,n): if bfs(n, w, 1, lambda que, i: que[i] == n): return w else: for w in range(2,n): if bfs(n, w, 1, lambda que, i: que[i] % w == 0) \ and bfs(n, w, n, lambda que, i: que[i] % w == 0): return w print(solve(int(input())))