#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

int main(){
	
	string s;
	cin >> s;
	vector<long long> cnt(10, 0);
	for(int i=0; i<s.size(); i++){
		if(i==1) continue;
		cnt[s[i]-'0']++;		
	}
	int ans[] = {20104,20063,19892,20011,19874,20199,19898,20163,19956,19841};

	int a = -1;
	int b = -1;
	for(int i=0; i<10; i++){
		//cout << cnt[i] << endl;
		if(cnt[i] > ans[i]) a = i;
		if(cnt[i] < ans[i]) b = i;
	}

	printf("%d %d\n", a,b);
	


	return 0;
}