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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nafiur Rahman Khadem Shafin
 */
public class Main {
	public static void main (String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader (inputStream);
		PrintWriter out = new PrintWriter (outputStream);
		TaskA solver = new TaskA ();
		solver.solve (1, in, out);
		out.close ();
	}
	
	static class TaskA {
		public void solve (int testNumber, InputReader in, PrintWriter out) {
/* number of digits can be 1e6 so can't run more than nlogn algo. Seems to be another out of range problem, but only weak point maybe
 * it has 1869. Okay as it's not a D problem, there is definitely a way. Assumption 1: 1869 can be rearranged in such a way so that
 * whatever might be the remainder by 7(0000) can be divisible ==> let's try calculating answer 01869,11869,21869,31869,41869,51869,61869
 * 0 ==> 01869 1 ==> 16198 2 ==> 21896 3 ==> 31689 4 ==> 41986 5 ==> 51968 6 ==> 61698 But still it's out of range as no idea of how to
 * find the prefix%7 as 1e6 char. Hurrah! By searching in net I have found a superb article on testing divisibility by 7 at geeksforgeeks
 * So now my plan is to seperate 1689 and all 0s and then run the magic formula*/
		/*String str = "11869";
		permutation ("", str);*/
			char[] orstr = in.next ().toCharArray (), ansos = new char[orstr.length+5];
			boolean ok1 = false, ok8 = false, ok6 = false, ok9 = false;
			long os = -1;
			int n = orstr.length, p = 10, cnt0 = 0, idx = 0;
			byte sign = -1;
			for (int i = n-1; i>=0; i--) {
				if ((ok1 || orstr[i] != '1') && (ok8 || orstr[i] != '8') && (ok6 || orstr[i] != '6') && (ok9 || orstr[i] != '9') && orstr[i] !=
																																			'0') {
					os += sign*p*(orstr[i]-'0');
					ansos[idx++] = orstr[i];
					p *= 10;
					if (p == 1000) {
						p = 1;
						sign *= -1;
					}
				}
				else if (orstr[i] == '0') {
					cnt0++;
				}
				else if (orstr[i] == '1') {
					ok1 = true;
				}
				else if (orstr[i] == '8') {
					ok8 = true;
				}
				else if (orstr[i] == '6') {
					ok6 = true;
				}
				else if (orstr[i] == '9') {
					ok9 = true;
				}
			}
			out.print (new StringBuilder (new String (ansos, 0, idx)).reverse ());
			if ((os+869)%7 == 0) {
				out.print (1869);
			}
			else if ((os+896)%7 == 0) {
				out.print (1896);
			}
			else if ((os+689)%7 == 0) {
				out.print (1689);
			}
			else if ((os+986)%7 == 0) {
				out.print (1986);
			}
			else if ((os+968)%7 == 0) {
				out.print (1968);
			}
			else if ((os+698)%7 == 0) {
				out.print (1698);
			}
			else {
				out.print (6198);
			}
			for (int i = 0; i<cnt0; i++) {
				out.print (0);
			}
			out.println ();
		}
		
	}
	
	static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;
		
		public InputReader (InputStream stream) {
			reader = new BufferedReader (new InputStreamReader (stream));
			tokenizer = null;
		}
		
		public String next () {
			while (tokenizer == null || !tokenizer.hasMoreTokens ()) {
				try {
					String str;
					if ((str = reader.readLine ()) != null) tokenizer = new StringTokenizer (str);
					else return null;//to detect eof
				} catch (IOException e) {
					throw new RuntimeException (e);
				}
			}
			return tokenizer.nextToken ();
		}
		
	}
}

