import sys input = sys.stdin.readline LIST=[[[0,1,2,4,5,6],[3,4,5,6]], [[2,5],[1,4]], [[0,2,3,4,6]], [[0,2,3,5,6]], [[1,2,3,5]], [[0,1,3,5,6]], [[0,1,3,4,5,6],[1,3,4,5,6]], [[0,2,5],[0,1,2,5]], [[]], [[0,1,2,3,5,6],[0,1,2,3,5]] ] def calc(S): NOW=[[0]*7] NNOW=[] for now in NOW: now2=[now] for s in S: #print(s) now3=[] for nowl in now2: #print(nowl) for ll in LIST[int(s)]: ni=nowl[:] for x in ll: ni[x]+=1 now3.append(ni[:]) now3.sort() now2=[] for x in now3: if now2 and now2[-1]==x: continue now2.append(x) #print(now2) NNOW+=now2 #print(NNOW) for x in NNOW: if len(set(x))==1: return True return False N=int(input()) for i in range(N,10**18+20): if calc(str(i))==True: print(i) break