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

/* 
Keep solving problems. 
*/

import java.util.*;
import java.io.*;

public class CF375A {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    int[] pow;
    void solve() throws IOException {
        char[] str = nextString().toCharArray();
        int n = str.length;
        int[] arr = new int[10];
        for(int i = 0; i < n; i++) {
            arr[str[i] - '0']++;
        }
        arr[1]--;
        arr[6]--;
        arr[8]--;
        arr[9]--;
        pow = new int[1000000 + 10];
        pow[0] = 1;
        for(int i = 1; i < pow.length; i++) {
            pow[i] = pow[i - 1] * 10;
            pow[i] %= 7;
        }
        int idx = 0;

        int[] res = new int[n];
        for(int i = 1; i < 10; i++) {
            for(int j = 0; j < arr[i]; j++) {
                res[idx + j] = i;
            }
            idx += arr[i];
        }
        int value = 0;
        for(int i = 0; i < idx; i++) {
            value += res[i] * pow[n - i - 1];
            value %= 7;
        }
        int[] perm = {1, 6, 8, 9};
        int rem = pow[arr[0]];

        while(true) {
            boolean tmp = check(perm, rem, value);
            if(tmp) {
                break;
            }
            tmp = next_permutation(perm);
            if(!tmp) {
                break;
            }
        }
        for(int i = 0; i < perm.length; i++) {
            res[idx + i] = perm[i];
        }

        char[] pr = new char[n];
        for(int i = 0; i < n; i++) {
            pr[i] = (char) ('0' + res[i]);
        }
        out(new String(pr));
    }
    public boolean check(int[] perm, int rem, int value) {
        int res = 0;
        for(int i = 0; i < perm.length; i++) {
            res += perm[i] * pow[perm.length - i - 1];
            res = res % 7;
        }
        return (res * rem + value) % 7  == 0;
    }
    boolean next_permutation(int[] p) {
        for (int a = p.length - 2; a >= 0; --a)
            if (p[a] < p[a + 1])
                for (int b = p.length - 1;; --b)
                    if (p[b] > p[a]) {
                        int t = p[a];
                        p[a] = p[b];
                        p[b] = t;
                        for (++a, b = p.length - 1; a < b; ++a, --b) {
                            t = p[a];
                            p[a] = p[b];
                            p[b] = t;
                        }
                        return true;
                    }
        return false;
    }
    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public CF375A() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CF375A();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}

