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.
# https://codeforces.com/problemset/problem/375/A

from itertools import permutations


#
#
# def div_seven(a):
#     if (int(a) % 7 == 0):
#         return a
#     a = list(a)
#     check = 0
#     for p in permutations(a):
#         temp = ''.join(i for i in p)
#         if (len(temp) == len(a)):
#             if (int(temp) % 7 == 0):
#                 print(temp)
#                 check = 1
#                 # break
#     if (check == 0):
#         print(0)
def div_seven(a):
    if (int(a) % 7 == 0):
        return a
    a = list(a)
    lst = ['1', '6', '8', '9']
    a.remove('1')
    a.remove('8')
    a.remove('6')
    a.remove('9')
    for p in permutations(lst):
        temp = a + list(p)
        temp = int(''.join(i for i in temp))
        if (int(temp) % 7 == 0):
            temp=str(temp)
            temp = temp + (len(a) + 4 - len(temp)) * '0'
            return temp
    return 0


a = input().strip()
print(div_seven(a))
