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 static java.util.Arrays.deepToString;

import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {

    static int rem(StringBuilder sb) {
        if(sb.length() == 0) {
            return 0;
        }
        int n = sb.length();
        int rem = 0;
        for(int i = 0; i < n; i++) {
            int num = Character.getNumericValue(sb.charAt(i));
            int cur = rem * 10  + num;
            rem = cur % 7;
        }
        return rem;
    }

    private static void solve() throws IOException {
        String s = next();
        StringBuilder sb = new StringBuilder();
        StringBuilder sb1 = new StringBuilder("1");
        boolean[] u1 = new boolean[10];
        for (int i = 0; i < s.length(); i++) {
            int num = Character.getNumericValue(s.charAt(i));
            if ((num == 1 || num == 6 || num == 8 || num == 9) && !u1[num]) {
                u1[num] = true;
                continue;
            }
            sb.append(s.charAt(i));
            sb1.append("0");
        }
        char[] a = new char[]{1, 6, 8, 9};

        int rem1 = rem(sb);
        int rem2 = rem(sb1);
        b1:
        for (int i = 0; i < 4; i++) {
            for (int ii = 0; ii < 4; ii++) {
                if (ii == i) continue;
                for (int iii = 0; iii < 4; iii++) {
                    if (iii == i || iii == ii) continue;
                    for (int iiii = 0; iiii < 4; iiii++) {
                        if (iiii == iii || iiii == ii || iiii == i) continue;
                        int x = a[i] * 1000 + a[ii] * 100 + a[iii] * 10 + a[iiii];
                        int rem3 =((x % 7 * rem2) % 7 + rem1) % 7;
                        if (rem3 == 0) {
                            out.println("" + x + sb.toString());
                            break b1;
                        }
                    }
                }
            }
        }
    }

    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter out;

    static void debug(Object... a) {
        System.err.println(deepToString(a));
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String line = br.readLine();
            if (line == null) {
                return null;
            }
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    public static void main(String[] args) {
        try {
            File file = new File("fn.in");
            InputStream input = System.in;
            OutputStream output = System.out;
            if (file.canRead()) {
                input = (new FileInputStream(file));
                output = (new PrintStream("fn.out"));
            }
            br = new BufferedReader(new InputStreamReader(input));
            out = new PrintWriter(output);
            solve();
            out.close();
            br.close();
        } catch (Throwable e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}