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.
# Author Name: Ajay Meena
# Codeforce : https://codeforces.com/profile/majay1638
import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout

# -------------- INPUT FUNCTIONS ------------------


def get_ints_in_variables(): return map(
    int, sys.stdin.readline().strip().split())


def get_int(): return int(sys.stdin.readline())


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()

# -------- SOME CUSTOMIZED FUNCTIONS-----------


def myceil(x, y): return (x + y - 1) // y

# -------------- SOLUTION FUNCTION ------------------


def permutaion(s, permt):
    if len(s) == 4:
        permt.append(s)
        return
    if not "1" in s:
        permutaion(s+"1", permt)
    if not "6" in s:
        permutaion(s+"6", permt)
    if not "8" in s:
        permutaion(s+"8", permt)
    if not "9" in s:
        permutaion(s+"9", permt)


def Solution():
    # Write Your Code Here
    n = get_string()
    cnt = 0
    for c in n:
        if c == "0":
            cnt += 1
    permt = []
    permutaion("", permt)
    ans = ""
    tmp = set()
    tmp.add("1")
    tmp.add("6")
    tmp.add("8")
    tmp.add("9")
    for c in n:
        if not c in tmp and c != "0":
            ans += c
        else:
            if c in tmp:
                tmp.remove(c)
    for v in permt:
        tmpans = ans
        tmpans += v
        for _ in range(cnt):
            tmpans += "0"
        if int(tmpans) % 7 == 0:
            print(tmpans)
            return

    print(0)


def main():
    # Take input Here and Call solution function
    Solution()


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