#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;
bool isPrime(int num);

int main(){
	int n;
	while(cin >> n, n){
		int prev = 0, next = 0;
		
		for(int i = n-2; i >= 3; i -= 2){
			if(isPrime(i)){
				prev = i;
				break;
			}
		}
		
		for(int i = n+2; i <= 50000; i += 2){
			if(isPrime(i)){
				next = i;
				break;
			}
		}
		
		cout << prev << " " << next << endl;
	}
	return 0;
}

bool isPrime(int num){
	if(num < 2)
		return false;
	
	for(int i = 2; i*i <= num; i++){
		if(num % i == 0)
			return false;
	}
	return true;
}
