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.*;
import java.math.*;

public class A implements Runnable {
	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer st;
	static Random rnd;

	private void solve() throws IOException {
		String s = nextToken();
		int n = s.length();
		int[] howMuch = new int[10];
		for (int i = 0; i < n; i++) {
			howMuch[s.charAt(i) - '0']++;
		}
		int lastRemain = 1, cursor = 0, resultRemain = 0;
		int[] result = new int[n];
		int[] needToStay = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 1 };
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < howMuch[i] - needToStay[i]; j++) {
				result[cursor++] = i;
				resultRemain = (resultRemain + i * lastRemain) % 7;
				lastRemain = (10 * lastRemain) % 7;
			}
		}
		int needRemain = (7 - resultRemain) % 7;
		int[] remains = new int[4];
		int[] digits = { 1, 6, 8, 9 };
		for (int i = 0; i < 4; i++) {
			remains[i] = lastRemain;
			lastRemain = (10 * lastRemain) % 7;
		}
		// out.println(Arrays.toString(remains) + " " + needRemain);
		// out.flush();
		int[] add = rec(0, 4, remains, digits, new boolean[4], new int[4], 0,
				needRemain);
		for (int i = 0; i < 4; i++) {
			result[cursor++] = add[i];
		}
//		int checkResult = 0;
//		lastRemain = 1;
//		for (int i = 0; i < n; i++) {
//			checkResult = (checkResult + result[i] * lastRemain) % 7;
//			lastRemain = (10 * lastRemain) % 7;
//		}
//		out.println(checkResult);
		for (int i = n - 1; i >= 0; i--) {
			out.print(result[i]);
		}
		out.print('\n');
	}

	private int[] rec(int step, int limit, int[] remains, int[] digits,
			boolean[] used, int[] history, int cur, int need) {
		if (step == limit) {
			return (cur == need) ? history : null;
		} else {
			for (int i = 0; i < 4; i++) {
				if (!used[i]) {
					used[i] = true;
					history[step] = digits[i];
					int[] tryResult = rec(step + 1, limit, remains, digits,
							used, history,
							(cur + remains[step] * digits[i]) % 7, need);
					if (tryResult != null) {
						return tryResult;
					}
					used[i] = false;
				}
			}
			return null;
		}
	}

	public static void main(String[] args) {
		// final boolean oldChecker = false;
		//
		// if (oldChecker)
		// new Thread(null, new Template(), "yarrr", 1 << 24).start();
		// else
		new A().run();
	}

	public void run() {
		try {
			final String className = this.getClass().getName().toLowerCase();

			try {
				in = new BufferedReader(new FileReader(className + ".in"));
				out = new PrintWriter(new FileWriter(className + ".out"));
				// in = new BufferedReader(new FileReader("input.txt"));
				// out = new PrintWriter(new FileWriter("output.txt"));
			} catch (FileNotFoundException e) {
				in = new BufferedReader(new InputStreamReader(System.in));
				out = new PrintWriter(System.out);
			}

			rnd = new Random();

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	private String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String line = in.readLine();

			if (line == null)
				return null;

			st = new StringTokenizer(line);
		}

		return st.nextToken();
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}