class Integer def prime? n = self.abs() return true if n == 2 return false if n == 1 || n & 1 == 0 d = n-1 d >>= 1 while d & 1 == 0 20.times do a = rand(n-2) + 1 t = d y = ModMath.pow(a,t,n) while t != n-1 && y != 1 && y != n-1 y = (y * y) % n t <<= 1 end return false if y != n-1 && t & 1 == 0 end return true end end module ModMath def ModMath.pow(base, power, mod) result = 1 while power > 0 result = (result * base) % mod if power & 1 == 1 base = (base * base) % mod power >>= 1; end result end end n = gets.to_i a = [4, 6, 8, 9, 10, 15, 16, 22, 12, 14, 20, 21, 24] b = [3, 5, 7, 7, 7, 7, 7, 7, 11, 13, 19, 19, 23] a.length.times do |i| if a[i] == n puts b[i] exit end end if !(n - 8).prime? puts 8 else puts 14 end