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.

Input

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 106 characters.

Output

Print a number in the decimal notation without leading zeroes — the result of the permutation.

If it is impossible to rearrange the digits of the number a in the required manner, print 0.

Examples

Input

1689


Output

1869


Input

18906


Output

18690

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;

public class C {

    public static void main(String args[]) throws Exception {
        int arr[] = {1869, 1968, 6918, 6198, 8691, 1986, 8196};
        C in = new C();
        in.init(System.in);
        String s = in.nextString();

        if (s.length() == 4) {
            System.out.println(arr[0]);
            return;
        }
        int arr1[] = new int[10];
        for (int x = 0; x < s.length(); x++) {
            arr1[s.charAt(x) - '0']++;
        }
        arr1[1]--;
        arr1[6]--;
        arr1[8]--;
        arr1[9]--;
        if (arr1[2] == 0 && arr1[3] == 0 && arr1[4] == 0 && arr1[5] == 0 && arr1[7] == 0 && arr1[1] == 0 && arr1[6] == 0 && arr1[8] == 0 && arr1[9] == 0) {
            StringBuffer a1 = new StringBuffer("");
            for (int x = 0; x < arr1[0]; x++) {
                a1.append(0);
            }
            System.out.println(arr[0] + a1.toString());
            return;
        }

        int rem = 0;
        StringBuffer a1 = new StringBuffer("");
        int arr2[] = {1, 3, 2, 6, 4, 5};

        int start = s.length()-1;
        //t arr3[] = {2,3,4,5,7,0};
        for (int x = 1; x < 10; x++) {
            for (int y = 0; y < arr1[x]; y++) {
                a1.append(x);
              //  System.out.println(arr2[start%6]);
                rem += arr2[start % 6]*x;
                start--;
                rem %= 7;
            }
        }
        for (int y = 0; y < arr1[0]; y++) {
            a1.append(0);
        }
       // System.out.println(a1.toString());
     //   System.out.println(rem);
        if (rem == 0) {
            System.out.println(a1.toString() + arr[0]);
        } else {
            System.out.println(a1.toString() + arr[7 - rem]);
        }

    }

    void init(InputStream in) {
        din = new DataInputStream(in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String nextString() throws Exception {
        StringBuffer sb = new StringBuffer("");
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        do {
            sb.append((char) c);
            c = read();
        } while (c > ' ');
        return sb.toString();
    }

    public char nextChar() throws Exception {
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        return (char) c;
    }

    public int nextInt() throws Exception {
        int ret = 0;
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        boolean neg = c == '-';
        if (neg) {
            c = read();
        }
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');
        if (neg) {
            return -ret;
        }
        return ret;
    }

    public long nextLong() throws Exception {
        long ret = 0;
        byte c = read();
        while (c <= ' ') {
            c = read();
        }
        boolean neg = c == '-';
        if (neg) {
            c = read();
        }
        do {
            ret = ret * 10 + c - '0';
            c = read();
        } while (c > ' ');
        if (neg) {
            return -ret;
        }
        return ret;
    }

    private void fillBuffer() throws Exception {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1) {
            buffer[0] = -1;
        }
    }

    private byte read() throws Exception {
        if (bufferPointer == bytesRead) {
            fillBuffer();
        }
        return buffer[bufferPointer++];
    }

    final private int BUFFER_SIZE = 1 << 17;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

}
