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.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.InputMismatchException;


public class OTHER {
	static long remainder,zeros;
	static String s = "",first,end;
	public static void main(String[] args) {
		MScanner sc = new MScanner();
		PrintWriter out = new PrintWriter(System.out);
		String in = sc.next();
		int[] freq = new int[10];
		for(int a=0;a<in.length();a++)
			freq[in.charAt(a)-'0']++;
		freq[1]--;
		freq[6]--;
		freq[8]--;
		freq[9]--;
		StringBuilder SB = new StringBuilder("");
		remainder = 0;
		long pow =1 ;
		for(int a=0;a<freq[0]+4;a++){
			pow*=10;
			pow%=7;
		}
		zeros = freq[0];
		for(int a=1;a<10;a++)
			while(freq[a]-->0){
				SB.append(a);
				remainder += pow * a;
				remainder%=7;
				pow*=10;
				pow%=7;
			}
		first = SB.reverse().toString();
		SB = new StringBuilder("");
		while(freq[0]-->0)SB.append(0);
		end= SB.toString();
		
		permuteS(new int[] {1,6,8,9});
		out.println(s);
		out.close();
	}


	
	static void permuteS(int[] array) {
		permute(new int[array.length], 0, new boolean[array.length], array);
	}
	static void permute(int perm[], int pos, boolean[] used, int[] array) {
		if(s.length()!=0)return;
		if (pos == perm.length) {
			
			String cur = perm[0]+""+perm[1]+""+perm[2]+""+perm[3];
			long pow = 1;
			long base = 0;
			for(int a=0;a<zeros;a++){
				pow*=10;
				pow%=7;
			}
			base = Integer.valueOf(cur);
			
			long val = base*pow;
			val%=7;
		//	System.out.println(cur+" "+val);
			val+=remainder;
			val%=7;
			
			if(val == 0){
				s = first+cur+end;
				
			}
			//System.out.println(cur+" "+val);
			return;
		}
		for (int pick = 0; pick < perm.length; pick++) {
			if (!used[pick]) {
				perm[pos] = array[pick];
				used[pick] = true;
				permute(perm, pos + 1, used, array);
				used[pick] = false;
			}
		}
	}

	static long GCD(long a, long b) {
		if (b == 0)
			return a;
		return GCD(b, a % b);
	}

	static class MScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public MScanner() {
			stream = System.in;
			// stream = new FileInputStream(new File("dec.in"));

		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

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

		int[] nextInt(int N) {
			int[] ret = new int[N];
			for (int a = 0; a < N; a++)
				ret[a] = nextInt();
			return ret;
		}

		int[][] nextInt(int N, int M) {
			int[][] ret = new int[N][M];
			for (int a = 0; a < N; a++)
				ret[a] = nextInt(M);
			return ret;
		}

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

		long[] nextLong(int N) {
			long[] ret = new long[N];
			for (int a = 0; a < N; a++)
				ret[a] = nextLong();
			return ret;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDouble(int N) {
			double[] ret = new double[N];
			for (int a = 0; a < N; a++)
				ret[a] = nextDouble();
			return ret;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] next(int N) {
			String[] ret = new String[N];
			for (int a = 0; a < N; a++)
				ret[a] = next();
			return ret;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}

		String[] nextLine(int N) {
			String[] ret = new String[N];
			for (int a = 0; a < N; a++)
				ret[a] = nextLine();
			return ret;
		}

	}
}