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.
s = input()
t = ""
dem0 = 0
dem1 = 0
dem6 = 0
dem8 = 0
dem9 = 0

for i in range(len(s)):
    if s[i] == '1':
        dem1 += 1
    elif s[i] == '6':
        dem6 += 1
    elif s[i] == '8':
        dem8 += 1
    elif s[i] == '9':
        dem9 += 1
    elif s[i] == '0':
        dem0 += 1
    else:
        t += s[i]

while dem1 != 1:
    t += '1'
    dem1 -= 1

while dem6 != 1:
    t += '6'
    dem6 -= 1

while dem8 != 1:
    t += '8'
    dem8 -= 1

while dem9 != 1:
    t += '9'
    dem9 -= 1

x = "1689"
y = "0" * dem0
ans = t + x + y

if int(ans) % 7 == 0:
    print(ans)
else:
    import itertools
    for perm in itertools.permutations(x):
        perm_str = ''.join(perm)
        ans = t + perm_str + y
        if int(ans) % 7 == 0:
            print(ans)
            break
