// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

vector<int> eratosthenes(const int &n) {
  vector<int> v(n);
  v[0] = v[1] = false;
  loop(i, 2, v.size()) v[i] = true;
  for (int i = 2; i * i < n; i++) {
    if (v[i]) {
      for (int j = i * 2; j < n; j += i) {
        v[j] = false;
      }
    }
  }
  return v;
}

void solve() {
  int n;
  while (cin >> n, n) {
    vi v = eratosthenes(n + 1);
    vi w;
    rep(i, v.size()) if (v[i]) w.pb(i);
    reverse(all(w));
    loop(i, 1, w.size()) {
      if (w[i - 1] == w[i] + 2) {
        cout << w[i] << ' ' << w[i - 1] << endl;
        break;
      }
    }
  }
}
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
using namespace std;

int main(){
  int h,w;
  int i,j;
  int flag;
  while(cin>>h>>w,h|w){
    int taikaku;
    int tmph=1111,tmpw=1111;
    taikaku=h*h+w*w;
    flag=false;
    for(i=1;i<150;i++){
      for(j=1;j<150;j++){
	//if(i==4&&j==8) cout<<"a"<<endl;
	if(i>=j||(i==h&&j==w)) continue;
	if(i*i+j*j==taikaku) {
	  if(h<i){
	    tmph=i;
	    tmpw=j;
	    flag=true;
	    break;
	  }
	}
	else if(i*i+j*j>taikaku&&i*i+j*j<tmph*tmph+tmpw*tmpw) {
	  tmph=i;
	  tmpw=j;
	}
      }
      if(flag) break;
    }
    cout<<tmph<<" "<<tmpw<<endl;
  }
  return 0;
}