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.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOError;
import java.io.IOException;
import java.io.InputStreamReader;;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Locale;
import java.util.Scanner;
import java.util.StringTokenizer;

public class algo_636 {
	static BufferedReader br;
	static PrintWriter pw;
	static StringTokenizer st;
	public static void main(String[] args)throws IOException {
		Locale.setDefault(Locale.US);
		br=new BufferedReader(new InputStreamReader(System.in));
		pw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		
		//gfile();
		char a[]=next().toCharArray();
		int b[]=new int[10];
		int c[]=new int[a.length];
		for (int i = 0; i < a.length; i++) {
			b[(int)a[i]-48]++;
		}
		int x=0;
		for (int i = 1; i <=9; i++) {
			if(i==1||i==6||i==8||i==9){
				for (int j = 1; j <=b[i]-1; j++){
					c[++x]=i;
					pw.print(i);
				}
			}else
				for (int j = 1; j <=b[i]; j++) {
					c[++x]=i;
					pw.print(i);
				}
		}
		int mod=0;
		for (int i = 1; i <=x; i++) {
			if(c[i]+mod*10>=7)
				mod=(mod*10+c[i])%7;
			else{
				if(i+1<=x)
				mod=(c[i]*10+c[i+1])%7;
				else
					mod=c[i];
				i++;
			}
		}
		int t[]=new int[5];
		t[1]=1;
		t[2]=6;
		t[3]=8;
		t[4]=9;
		String ss = "";
		for (int i = 1; i <=4; i++) {
			ss += t[i] + "";
		}
		if ((Integer.parseInt(ss)+mod*10000) % 7 == 0) {
			for (int i = 1; i <=4; i++) {
				pw.print(t[i]);
			}
			if(b[0]!=0){
				for (int j = 1; j <=b[0]; j++)
					pw.print(0);
				}
			pw.close();
			return;
		}
		int i = 4;
		while (i > 1) {
			if (t[i] > t[i - 1]) {
				for (int j =4; j >= i; j--)
					if (t[j] > t[i - 1]) {
						int r = t[j];
						t[j] = t[i - 1];
						t[i - 1] = r;
						break;
					}
				Arrays.sort(t,i,5);
				ss = "";
				for (int j2 = 1; j2 <=4; j2++) {
					ss += t[j2] + "";
				}
				if ((Integer.parseInt(ss)+mod*10000) % 7 == 0) {
					for (int j = 1; j <=4; j++) {
						pw.print(t[j]);
					}
					if(b[0]!=0)
						for (int j = 1; j <=b[0]; j++) {
							pw.print(0);
						}
					pw.close();
					return;
				}
				i =4;
			} else
				i--;
		}
		pw.close();
	}
	private static void gfile() throws IOException{
		br=new BufferedReader(new FileReader(new File("input.txt")));
		pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
	}
	private static long nextLong()throws IOException {
		return Long.parseLong(next());
	}
	private static double nextDouble()throws IOException {
		return Double.parseDouble(next());
	}
	private static int nextInt()throws IOException {
		return Integer.parseInt(next());
	}
	private static String next()throws IOException{
		while(st==null||!st.hasMoreTokens())
			st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
}