# coding:utf-8 pi_count = [20104,20063,19892,20011,19874,20199,19898,20163,19956,19841] s = input() a = 0 b = 0 for i in range(10): if s.count(str(i)) > pi_count[i]: a = i if s.count(str(i)) < pi_count[i]: b = i print(a,b)