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

public class Main{
    String ans;
    int []value ={1,6,8,9};
    int []perm;
    boolean []used;
    
    private void doit(){
        InStream sc = new InStream();
        while(sc.hasNext()){
            String s = sc.next();
            int [] acc = new int[10];
            for(int i = 0; i < s.length(); i++){
                acc[s.charAt(i) - '0']++;
            }
            acc[1]--;
            acc[6]--;
            acc[8]--;
            acc[9]--;
            
            StringBuilder sb = new StringBuilder();
            long mod = 0, mod2 = 1;
            for(int i = 0; i < 10; i++){
                for(int j = 0; j < acc[i]; j++){
                    sb.append(i);
                    mod = (i * mod2) + mod;
                    mod2 = (mod2 * 10) % 7;
                    mod%= 7;
                }
            }
            sb.reverse();
            
            ans = null;
            used = new boolean[4];
            perm = new int[4];
            
            dfs(0, sb.toString(), mod, mod2);
            System.out.println(ans == null ? "0" : ans);
        }
    }
    
    private boolean dfs(int deep, String string, long mod, long mod2) {
        if(deep == 4){
            long mod3 = 0, m = mod2;
            for(int i = 0; i < 4; i++){
                mod3 = ((perm[i] * m) + mod3) % 7;
                m = (m * 10) % 7;
            }
            long m2 = (mod3 + mod) % 7;
            if(m2 == 0){
                StringBuilder sb = new StringBuilder();
                for(int i = 3; i >= 0; i--){
                    sb.append(perm[i]);
                }
                sb.append(string);
                ans = sb.toString();
                return true;
            }
            
            return false;
        }
        
        for(int i = 0; i < 4; i++){
            if(used[i]) continue;
            used[i] = true;
            perm[deep] = value[i];
            boolean res = dfs(deep + 1, string, mod, mod2);
            if(res){
                return true;
            }
            perm[deep] = 0;
            used[i] = false;
        }
        return false;
    }

    class InStream {
        BufferedReader in;
        StringTokenizer st;

        public InStream() {
            this.in = new BufferedReader(new InputStreamReader(System.in));
            this.st = null;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (Exception e) {
                }
            }
            return st.nextToken();
        }

        boolean hasNext() {
            try {
                st = new StringTokenizer(in.readLine());
                return true;
            } catch (Exception e) {
                return false;
            }
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
    
    
    private void debug(Object... o) {
        System.out.println("debug = " + Arrays.deepToString(o));
    }

    public static void main(String[] args) {
        new Main().doit();
    }
}