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.
# print(1869 % 7)
# print(1896 % 7)
# print(1689 % 7)
# print(1698 % 7)
# print(1986 % 7)
# print(1968 % 7)
# print(6891 % 7)

cnt_array =[0 for _ in range(10)]
s = input()
for i in range(len(s)) :
    cnt_array[int(s[i])]+=1 
rem = 0 
l=[]
for i in range(1,10) : 
    if (i!=1 and i!=6 and i!=8 and i!=9) : 
        while(cnt_array[i]>0) :
            # rem*=7
            cnt_array[i]-=1
            l.append(str(i))
            rem*=10
            rem+= i 
            rem%=7
    else : 
        while(cnt_array[i]>1) :
            l.append(str(i))
            rem*=10
            rem+= i 
            rem%=7
            cnt_array[i]-=1
while(cnt_array[0]>0) :
    rem*=10
    rem%=7
    l.append(str(0))
    cnt_array[0]-=1
# print(l)
# print(rem)
rem*=10000
rem%=7
if (rem == 0) : 
    l.append(1)
    l.append(8)
    l.append(6)
    l.append(9)
elif (rem==1):
    l.append(1)
    l.append(8)
    l.append(9)
    l.append(6)
elif (rem==2) : 
    l.append(1)
    l.append(9)
    l.append(8)
    l.append(6)
elif (rem==3):
    l.append(1)
    l.append(6)
    l.append(9)
    l.append(8)
elif (rem==4) : 
    l.append(6)
    l.append(9)
    l.append(8)
    l.append(1)
elif (rem==5) : 
    l.append(1)
    l.append(6)
    l.append(8)
    l.append(9)
else :
    l.append(1)
    l.append(9)
    l.append(6)
    l.append(8)
# print(l)
for i in range(len(l)) : 
    l[i] =str(l[i])
# print(l)
s =''.join(l)
print(s)
# print(int(s) % 7)



# for 
# print(1869 % 7)
