You have number *a*, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.

Number *a* doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resulting number also mustn't contain any leading zeroes.
The first line contains positive integer *a* in the decimal record. It is guaranteed that the record of number *a* contains digits: 1, 6, 8, 9. Number *a* doesn't contain any leading zeroes. The decimal representation of number *a* contains at least 4 and at most 10<sup class="upper-index">6</sup> characters.
ans=[1,6,8,9]
rem=[]
from collections import *
al=defaultdict(int)
for i in range(len(ans)):
    for j in range(len(ans)):
        for m in range(len(ans)):
            for t in range(len(ans)):
                re=[i,j,m,t]
                if(len(set(re))==4):
                    q=pow(10,3)*ans[i]+(pow(10,2)*ans[j])+(pow(10,1)*ans[m])+(ans[t])
                    if(al[q%7]==0):
                        
                        rem.append([q%7,q])
                       
                        al[q%7]=1

s=input()
rem.sort()
ans=[]
for i in range(len(s)):
    ans.append(int(s[i]))
count=0
ans.remove(1)
ans.remove(6)
ans.remove(8)
ans.remove(9)
i=0

while(i<len(ans)):
   
    if(i==0):
        while(i<len(ans) and ans[i]==0):
            count+=1
            i+=1
        i+=1
    else:
        i+=1
temp=[]
for i in range(count,len(ans)):
    temp.append(ans[i])

if(len(temp)==0):
    s=str(rem[0][1])+'0'*count
    print(s)
    exit()
else:
    fin=0
    print(temp)
    for i in range(len(temp)):
        fin+=(pow(10,len(temp)-i-1,7)*(temp[i]%7))%7
        fin=fin%7
    m=''
    m=str(temp)+str(rem[fin][1])+'0'*count
    print(m)
    
        
        
    
    
