import sys input=lambda: sys.stdin.readline().rstrip() a,b=map(int,input().split()) aa,bb=str(a),str(b) def f(x): x=x.replace("4","a") x=x.replace("7","4") x=x.replace("a","7") return x aa=int(f(aa)) bb=int(f(bb)) if aa>bb: print(a) else: print(b)