$primes = [2,3]

def is_prime?(n)
	i = 0
	while $primes[i] <= Math.sqrt(n).to_i
		return false if n % $primes[i] == 0
		i += 1
	end
	return true
end

def next_prime(n)
	n += 1 if n % 2 == 0
	loop do
		return n if is_prime?(n)
		n += 2
	end
end

def make_prime(n)
	while $primes[-1] <= n
		$primes << next_prime($primes[-1]+1)
	end
end

def print_prime(n)
	if is_prime?(n)
		i = $primes.index(n)
		puts "#{$primes[i-1]} #{$primes[i+1]}"
	else
		i = 0
		i += 1 while $primes[i] < n
		print "#{$primes[i-1]} #{$primes[i]}"
	end
	puts ""
end

while gets
	n = $_.to_i
	if n < 3 || 50000 < n
		puts "n must be in the range (3..50000)"
		next
	end
	make_prime(n) if $primes[-2] < n
	print_prime(n)
end