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.
import sys
input = sys.stdin.readline
# import bisect #-->For bisect.bisect_left=lower_bound and bisect_right=upper_bound

s = input()
l = [*s][:-1]
# print(l)
d = {7:"1869", 1:"1968", 2:"1689", 3:"6198", 4:"1698", 5:"1986", 6:"1896"}
s1 = ""
c1, c6, c8, c9 = 0, 0, 0, 0
for i in range(len(l)):
    if (l[i] == "1" and c1 < 1):
        l[i] = -1
        c1 += 1
    elif (l[i] == "6" and c6 < 1):
        l[i] = -1
        c6 += 1
    elif (l[i] == "8" and c8 < 1):
        l[i] = -1
        c8 += 1
    elif (l[i] == "9" and c9 < 1):
        l[i] = -1
        c9 += 1
    else:
        s1 += l[i]
if (s1 != ""):
    n = int(s1)*10000
    if (n%7 == 0):
        s1 += d[7 - n%7]
    elif (n%7 == 1):
        s1 += d[7 - n%7]
    elif (n%7 == 2):
        s1 += d[7 - n%7]
    elif (n%7 == 3):
        s1 += d[7 - n%7]
    elif (n%7 == 4):
        s1 += d[7 - n%7]
    elif (n%7 == 5):
        s1 += d[7 - n%7]
    elif (n%7 == 6):
        s1 += d[7 - n%7]
    else:
        s1 += (d[7] + "0"*(len(s) - 5))
else:
    s1 += (d[7] + "0"*(len(s) - 5))
if (s1[0] != "0"):
    print(s1)
else:
    x = s1.count("0")
    s1 = s1[x:] + "0"*x
    print(s1)