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

using namespace std;
bool isPrime(int num);

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

bool isPrime(int num){
	if(num < 2)
		return false;
	else if(num == 2)
		return true;
	else if(num % 2 == 0)
		return false;
	
	double snum = sqrt(num);
	for(int i = 3; i <= snum; i += 2){
		if(num % i == 0)
			return false;
	}
	return true;
}
