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.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class DivisibleBySeven {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        
        String A = sc.next();
        
        int[] freq = new int[10];
        int[] orig = new int[A.length()];
        for (int i = 0; i < A.length(); i++) {
            orig[i] = A.charAt(i) - '0';
            freq[orig[i]]++;
        }
        
        freq[1]--;
        freq[6]--;
        freq[8]--;
        freq[9]--;
        
        int[] arr = new int[A.length()];
        int idx = arr.length - 1;
        for (int i = 1; i < 10; i++) {
            for (int j = 0; j < freq[i]; j++) {
                arr[idx--] = i;
            }
        }
        
        int[] mod = new int[A.length()];
        int[] pow10 = { 1, 10, 100, 1000, 10000, 100000 };
        for (int i = 0; i < mod.length; i++) {
            mod[i] = pow10[i % 6] % 7;
        }
        
        int currMod = 0;
        for (int i = orig.length - 1; i > idx; i--) {
            currMod += (mod[i] * arr[i]);
            currMod %= 7;
        }
        
        int[][] validPerms = new int[7][];
        int[][] perms = getPermutations(4, 4);
        int[] given = { 1, 6, 8, 9 };
        for (int[] perm : perms) {
            int newMod = 0;
            for (int i = 0; i < 4; i++) {
                newMod += (given[perm[i]] * mod[idx - i]);
            }
            validPerms[newMod % 7] = perm;
        }
        
        int needed = (7 - currMod) % 7;
        for (int i = 0; i < 4; i++) {
            arr[idx - i] = given[validPerms[needed][i]];
        }
        
        StringBuilder sb = new StringBuilder();
        for (int i = arr.length - 1; i >= 0; i--) {
            sb.append(arr[i]);
        }
        System.out.println(sb.toString());
    }

    /**
     * Method for computing permutations.  Returns an array of int[], which contains k elements from { 0, 1, ..., n - 1 }.
     * Each int[] will be sorted in ascending order, and they array of int[] will be sorted ascending as well.
     */
    public static int[][] getPermutations(int n, int k)
    {
        ArrayList<int[]> lst = new ArrayList<int[]>();
        int[] arr = new int[k];
        boolean[] used = new boolean[n];
        permutationHelper(n, k, 0, arr, used, lst);
        return lst.toArray(new int[0][]);
    }

    /**
     * Helper method for computing permutations.  Used by GetPermutations(...).
     */
    private static void permutationHelper(int n, int k, int t, int[] curr, boolean[] used, ArrayList<int[]> lst)
    {
        if (t == k)
        {
            int[] copy = new int[k];
            System.arraycopy(curr, 0, copy, 0, k);
            lst.add(copy);
            return;
        }

        for (int i = 0; i < n; i++)
        {
            if (used[i])
                continue;

            curr[t] = i;
            used[i] = true;
            permutationHelper(n, k, t + 1, curr, used, lst);
            used[i] = false;
        }
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        
        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

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

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

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

        String nextLine() {
            String str = "";
            try { str = br.readLine(); }
            catch (IOException e) { e.printStackTrace(); }
            return str;
        }
    }
}