m={4=>3,6=>5,8=>7,9=>7,10=>7,15=>7,16=>7,22=>7, 12=>11,14=>13,20=>19,21=>19,24=>23,25=>23} def powmod(a,k,m) return 1 if k == 0 t = powmod(a, k / 2, m) t = t * t % m t = t * a % m if k.odd? return t end def is_sosu(n) return false if n<2 return true if n<4 return false if n.even? d = n-1 d >>= 1 while d.even? 100.times do a = rand(n-1) + 1 y = powmod(a, d, n) t = d while t != n-1 and y != 1 and y != n-1 y = (y*y) % n t <<= 1 end return false if y!=n-1 and t.even? end return true end require 'prime' def isprime(n) if n < 100000 n.prime? else is_sosu n end end n=gets.chomp.to_i p m[n]?m[n]:(n%8==1&&isprime(n-8))?14:8