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.
#prefix = [1869,6189,1689,6198,1698,9861,1896]
#           0    5    3    1    6    4    2 

prefix = ["1869", "6198", "1896", "1689", "9861", "6189","1698"]
strs = input()
dicts = {}

for i in strs:
    if i not in dicts:
        dicts[i] = 1 
    else:
        dicts[i] += 1 
left = []
right = []
if "0" in dicts:
    for i in range(dicts["0"]):
        right.append("0")
    del dicts["0"]
for key, value in dicts.items():
    if key == "1" or key == "6" or key == "8" or key == "9":
        value -= 1 
    for i in range(value):
        left.append(key)
# print(dicts)
# print(left)
left = sorted(left)
# print(left)
leftstr =  "".join(left)
if len(left) == 0 and len(right) == 0 :
    print(1869)
elif len(left) == 0 :
    print(str(1869) + "0" * len(right) )
elif len(right) == 0 :
    leftnum= int(leftstr)
    rem = leftnum % 7 
    print(leftstr + prefix[rem])
else:
    leftnum= int(leftstr)
    rem = leftnum % 7 
    ans = leftstr + prefix[rem] + "0" * len(right)
    print(ans)
    
    

