n=[20104,20063,19892,20011,19874,20199,19898,20163,19956,19841] s=input() w=a=0 for i in range(10): c=s.count(str(i)) if c+1==n[i]: a=i if c-1==n[i]: w=i print(a,w)