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

using namespace std;
bool isPrime(int num);

int main(){
	int n;
	while(cin >> n, n){
		for(int i = n-2; i >= 3; i -= 2){
			if(isPrime(i) ){
				cout << i;
				break;
			}
		}
		
		for(int i = n+2; i <= 50000; i += 2){
			if(isPrime(i)){
				cout << " " << i << endl;
				break;
			}
		}
	}
	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;
}
