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.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.StringTokenizer;

public class DivisibleBy7 {

	static boolean[] vis;
	static ArrayList<String> perms = new ArrayList<>();
	static void perm(String s)
	{
		if(s.length() == 4)
			perms.add((s));
		else
			for(int i=0;i<arr.length;i++)
				if(!vis[i])
				{
					vis[i] = true;
					perm(s + arr[i]);
					vis[i] = false;
				}
	}
	static int[] arr;
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		arr = new int[]{9 , 8 , 6 , 1};
		vis =  new boolean[4];
		perm("");
		String s = sc.next();
		int[] occ = new int[10];
		for(int i=0;i<s.length();i++)
			occ[s.charAt(i) - '0']++;
		occ[9]--;
		occ[8]--;
		occ[6]--;
		occ[1]--;
		
		StringBuilder ans = new StringBuilder();
		
		int Nmod7 = 0;
		int pow = 1;
		for(int i=1;i<10;i++)
			for(int j=0;j<occ[i];j++)
				ans.append(i);
		for(int i=0;i<occ[0];i++)
			pow = (pow*10)%7;
		int st = pow;
		pow = (pow*10)%7;
		pow = (pow*10)%7;
		pow = (pow*10)%7;
		pow = (pow*10)%7;
		
		for(int i=ans.length() - 1;i>=0;i--)
		{
			int cur = ans.charAt(i) - '0';
			Nmod7 = (Nmod7 + (cur * pow)%7)%7;
			pow = (pow*10)%7;
		}
		String good = "";
		for(int i=0;i<perms.size();i++)
		{
			String x = perms.get(i);
			int in = Nmod7;
			int poww = st;
			for(int j=x.length() - 1;j>=0;j--)
			{
				int xx = x.charAt(j) - '0';
				in = (in + (poww * xx)%7)%7;
				poww = (poww * 10)%7;
			}
			if(in == 0)
			{
				good = x;
				break;
			}
		}
		ans.append(good);
		for(int i=0;i<occ[0];i++)
			ans.append(0);
		PrintWriter pw = new PrintWriter(System.out);
		pw.println(ans.toString());
		pw.flush();
		
	}
	static class Scanner{
		StringTokenizer st;BufferedReader br;
		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
		public Scanner(String s) throws FileNotFoundException{	br = new BufferedReader(new FileReader(new File(s)));}
		public String next() throws IOException 
		{while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());return st.nextToken();}
		public int nextInt() throws IOException {return Integer.parseInt(next());}
		public long nextLong() throws IOException {return Long.parseLong(next());}
		public String nextLine() throws IOException {return br.readLine();}
		public double nextDouble() throws IOException {return Double.parseDouble(next());}
		public boolean ready() throws IOException {return br.ready();}
	}
}
