require 'Prime' n = gets.to_i def func(n) arr = [-1,-1,-1,-1,3,0,5,0,7,7,7,0,11,0,13,7,7,0,8,0,19,19,7,0,23,23,8,8,8,0,8,0,8,8,8,8,8,0,8,8,8,0,8,0,8,8,8,0,-1] if(n<48) then return arr[n] end if n%8==1 && Prime.prime?(n-8) then return 14 else return 8 end end puts func(n)