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 int wanted;
	static StringBuilder rem;
	static int[]arr= {1,6,8,9};
	static int[]powersOf10;
	static void generate(int i,StringBuilder cur,int curMod,int power) {
		if(i>=4) {
			if(curMod==wanted) {
				if(rem==null) {
					rem=cur;
				}
			}
			return;
		}
		for(int j=0;j<4;j++) {
			boolean alreadyput=false;
			for(int k=i-1;k>=0;k--) {
				if(arr[j]==(cur.charAt(k)-'0')) {
					alreadyput=true;
				}
			}
			if(alreadyput)continue;
			StringBuilder tmp=new StringBuilder();
			tmp.append(cur);
			tmp.append(arr[j]);
			int digit=(arr[j]*powersOf10[power])%7;
			generate(i+1, tmp, (curMod+digit)%7,power-1);
		}
	}
	static void main() throws Exception{
		HashSet<Integer>hs=new HashSet<>();
		hs.add(1);
		hs.add(6);
		hs.add(8);
		hs.add(9);
		char[]in=sc.nextLine().toCharArray();
		int[]nums=new int[10];
		for(char c:in) {
			nums[c-'0']++;
		}
		powersOf10=new int[in.length];
		powersOf10[0]=1;
		for(int i=1;i<in.length;i++) {
			powersOf10[i]=(powersOf10[i-1]*10)%7;
		}
		int curPower=in.length-1;
		int mod=0;
		for(int i=9;i>0;i--) {
			if(hs.contains(i)) {
				nums[i]--;
			}
			for(int j=0;j<nums[i];j++) {
				pw.print(i);
				int curDigit=(i*powersOf10[curPower--])%7;
				mod=(mod+curDigit)%7;
			}
		}
		wanted=(7-mod)%7;
		generate(0, new StringBuilder(), 0,curPower);
		pw.print(rem);
		while(nums[0]>0) {
			pw.print(0);
			nums[0]--;
		}
	}
	public static void main(String[] args) throws Exception{
		pw=new PrintWriter(System.out);
		sc = new MScanner(System.in);
		int tc=1;
		while(tc-->0) main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}