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 Main {
    
    
    static InputReader in;
    static PrintWriter out;
        
    public static void main(String[] args) throws IOException{
        //InputStream ins = new FileInputStream("E:\\rush.txt");
        InputStream ins = System.in;
        in = new InputReader(ins);
        out = new PrintWriter(System.out);
        //code start from here
        new Task().solve(in, out);
        out.close();
    }
    
    static int N = 50000;
    static class Task{
        
    	int cnt[] = new int[10];
    	int a[] = {0,1,6,8,9};
    	int b[] = new int[10];
    	boolean bo[] = new boolean[5];
    	int n;
    	String s;
    	int cur = 0;
    	
    	boolean dfs(int dep,int now) {
    		if (dep==5) {
    			int temp = now;
    			for (int i = 1;i <= 4;i++) {
    				temp = temp*10 + b[i];
    				temp = temp%7;
    			}
    			if (temp==0) {
    				for (int i = 1;i <= 4;i++) {
    					out.print(b[i]);
    				}
    				return true;
    			}
    			return false;
    		}
    		for (int i = 1;i <= 4;i++)
    			if (!bo[i]) {
    				bo[i] = true;
    				b[dep] = a[i];
    				if (dfs(dep+1,now)) return true;
    				bo[i] = false;
    			}
    		return false;
    	}
        
        public void solve(InputReader in,PrintWriter out) {
        	s = in.next();
        	for (int i = 0;i < (int)s.length();i++) {
        		int key = s.charAt(i)-'0';
        		if (key==1 && cnt[1]==0) {
        			cnt[1] = 1;
        		}else if (key==6 && cnt[6]==0){
        			cnt[6] = 1;
        		}else if (key==8 && cnt[8]==0) {
        			cnt[8] = 1;
        		}else if (key==9 && cnt[9]==0) {
        			cnt[9] = 1;
        		}else {
        			cnt[key]++;
        			if (key!=0) {
        				out.print(key);
            			cur = cur * 10 + key;
            			cur = cur % 7;
        			}
        		}
        	}
        	dfs(1,cur);
        	
        	
        	for (int i = 1;i <= cnt[0];i++) {
        		out.print(0);
        	}
        }
    }

    

    static class InputReader{
        public BufferedReader br;
        public StringTokenizer tokenizer;
        
        public InputReader(InputStream ins) {
            br = new BufferedReader(new InputStreamReader(ins));
            tokenizer = null;
        }
        
        public String next(){
            while (tokenizer==null || !tokenizer.hasMoreTokens()) {
                try {
                tokenizer = new StringTokenizer(br.readLine());
                }catch(IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        
        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}