#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;
		int next = 0;
		for(int i = 2; (n-i) >= 3 && (n+i) <= 50000; i += 2){
			if(isPrime(n-i) && prev == 0)
				prev = n-i;
			if(isPrime(n+i) && next == 0)
				next = n+i;
		}
		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;
}
