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.*;
import java.util.*;

public class A {

    public static void main(String[] args) throws IOException {
        A solver = new A();
        solver.solve();
    }

    private void solve() throws IOException {
        FastScanner sc = new FastScanner(System.in);
//        sc = new FastScanner("1689");
//        sc = new FastScanner("18906");

        char[] line = sc.next().toCharArray();
        int[] digits = new int[10];
        for (char c : line) {
            digits[c - '0']++;
        }

        int num = 0;
        num = get(num, 1, digits[1] - 1);
        num = get(num, 2, digits[2]);
        num = get(num, 3, digits[3]);
        num = get(num, 4, digits[4]);
        num = get(num, 5, digits[5]);
        num = get(num, 6, digits[6] - 1);
        num = get(num, 7, digits[7]);
        num = get(num, 8, digits[8] - 1);
        num = get(num, 9, digits[9] - 1);

        int[] p = {1, 6, 8, 9};
        do {
            int X = p[0] + p[1] * 10 + p[2] * 100 + p[3] * 1000 + num * 10000;
            if (X % 7 == 0) break;
        } while (nextPermutation(p));

        StringBuilder sb = new StringBuilder();

        put(sb, 1, digits[1] - 1);
        put(sb, 2, digits[2]);
        put(sb, 3, digits[3]);
        put(sb, 4, digits[4]);
        put(sb, 5, digits[5]);
        put(sb, 6, digits[6] - 1);
        put(sb, 7, digits[7]);
        put(sb, 8, digits[8] - 1);
        put(sb, 9, digits[9] - 1);
        put(sb, p[3], 1);
        put(sb, p[2], 1);
        put(sb, p[1], 1);
        put(sb, p[0], 1);
        put(sb, 0, digits[0]);

        System.out.println(sb.toString());
    }

    private void put(StringBuilder sb, int digit, int count) {
        for (int i = 0; i < count; i++) {
            sb.append(digit);
        }
    }

    private int get(int num, int digit, int count) {
        for (int i = 0; i < count; i++) {
            num *= 10;
            num += digit;
            num %= 7;
        }
        return num;
    }

    private static boolean nextPermutation(int[] a) {
        int N = a.length;
        int i = N - 2;
        for (; i >= 0; i--) {
            if (a[i] < a[i + 1]) break;
        }
        if (i < 0) return false;
        for (int j = N - 1; j >= i; j--) {
            if (a[j] > a[i]) {
                int temp = a[i];
                a[i] = a[j];
                a[j] = temp;
                break;
            }
        }
        for (int j = i + 1; j < (N + i + 1) / 2; j++) {
            int temp = a[j];
            a[j] = a[N + i - j];
            a[N + i - j] = temp;
        }
        return true;
    }

    private static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public FastScanner(InputStream in) throws IOException {
            br = new BufferedReader(new InputStreamReader(in));
        }

        public FastScanner(File file) throws IOException {
            br = new BufferedReader(new FileReader(file));
        }

        public FastScanner(String s) {
            br = new BufferedReader(new StringReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                    return "";
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }

}
