M=50 comb=[[0]*M for m in range(M)] comb[0][0]=1 for i in range(M): for j in range(M): if i: comb[i][j]+=comb[i-1][j] if j: comb[i][j]+=comb[i][j-1] def cnt(d,x): retu=0 for c in range(d): if (c*5+x+5)%3==0: retu+=comb[d-1-c][c] return retu d=0 N=int(input())-1 while cnt(d,0)<=N: N-=cnt(d,0) d+=1 ans_lst=[None]*d ans_lst[0]=5 cur=0 for i in range(d-1,0,-1): if cnt(i,cur+3)<=N: N-=cnt(i,cur+3) ans_lst[i]=5 cur+=5 else: ans_lst[i]=3 print(*ans_lst[::-1],sep="")