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
import math
from sys import stdin, stdout
from itertools import permutations
 
# TAKE INPUT
def get_ints_in_variables():
    return map(int, sys.stdin.readline().strip().split())
def get_int(): return int(input())
def get_ints_in_list(): return list(
    map(int, sys.stdin.readline().strip().split()))
def get_list_of_list(n): return [list(
    map(int, sys.stdin.readline().strip().split())) for _ in range(n)]
def get_string(): return sys.stdin.readline().strip()
 
def main():
    # Write Your Code Here
    a = input()
    arr = []
    for i in range(0, 10):
        arr.append(0)
    for i in range(0, len(a)):
        arr[int(a[i])] += 1
    
    arr[1] -= 1
    arr[6] -= 1
    arr[8] -= 1
    arr[9] -= 1


    res1 = ""
    for i in range(1,10):
        while arr[i] > 0:
            res1 += str(i)
            arr[i] -= 1
    
    res3 = ""
    while arr[0] > 0:
        res3 += "0"
        arr[0] -= 1
    
    permuArr = permutations("1689")
    for perm in list(permuArr):
        res2 = ''.join(perm)
        tmp = res1+res2+res3
        tmp = int(tmp)
        if tmp % 7 == 0:
            print(tmp)
            return
    print(0)
    return
    
    

#  calling main Function
if __name__ == "__main__":
    main()