require 'prime'
$prime_array = []
Prime.each(999999) {|num|
	$prime_array.push(num)
}


def judge_prime_with_index(num)
	if $prime_array.include?(num)
		return $prime_array.index(num) + 1
	end
	
	return nil
end

while input = gets
	n = input.strip.to_i
	count = 0
	n.downto(2) {|num|
		result = judge_prime_with_index(num)
		if result != nil
			count = result
			break
		end
	}
	puts count
end