import re

s = "0207a97"
l = [(int(i), i) for i in re.findall('\d+',s) if '9' not in i]
if len(l)>0:
    print(max(l, key=lambda x: x[0])[1])