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.
# ﷽
from collections import defaultdict
from itertools import combinations, permutations
import sys
input = lambda: sys.stdin.readline().strip()
def inlst():return [int(i) for i in input().split()]
s='1689'
d=defaultdict(str)
for i in permutations(s,len(s)):
        d[int("".join(i))%7]=str("".join(i))
# print(d.values())
def solve():
    n=list(input())
    
    for i in s:
        n.remove(i)
    if  not n or len(set(n))==1 and '0' in n:
           print( d[0]+'0'*len(n));return
    while n[0]=='0':n.append(n.pop(0))
    tmp=(int("".join(n))*10**4)%7


    print( "".join(n)+d[(7-tmp)%7])

    

if __name__ == "__main__":
    # for i in range(int(input())):
        solve()
