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.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;

public class DivisibleBySeven {

	private static final boolean DEBUG = false;
	private static final boolean TEST = false;

	public static void main(String[] args) {

		try {

			final BufferedReader in;
			final OutputWriter out;

			if (DEBUG) {

				final String fileIn = DivisibleBySeven.class.getSimpleName().toLowerCase() + ".in";
				final String fileOut = DivisibleBySeven.class.getSimpleName().toLowerCase() + ".out";

				in = new BufferedReader(new FileReader(fileIn));
				out = new OutputWriter(new FileWriter(fileOut));
			} else {

				in = new BufferedReader(new InputStreamReader(System.in));
				out = new OutputWriter(new OutputStreamWriter(System.out));
			}

			new DivisibleBySeven().solve(in, out);

			out.close();

		} catch (Exception ex) {

			ex.printStackTrace();
		}
	}

	private final void solve(final BufferedReader in, final OutputWriter out) throws Exception {

		if (TEST) {

			for (int i = 1000; i <= 10000000; ++i) {
				String s = String.valueOf(i);

				int okMask = 0;
				for (char ch : s.toCharArray()) {
					if (ch == '1') {
						okMask |= 1;
					}
					if (ch == '6') {
						okMask |= 2;
					}
					if (ch == '8') {
						okMask |= 4;
					}
					if (ch == '9') {
						okMask |= 8;
					}
				}

				if (okMask != 15) {
					continue;
				}

				String result = solveForString(s);

				boolean isOk = true;

				String t = "";

				if ("0".equals(result)) {
					isOk = (t = dfs0(0, new boolean[s.length()], new int[s.length()], s)) == null;
				} else {
					int[] count = new int[10];
					for (char ch : s.toCharArray()) {
						++count[ch - '0'];
					}
					for (char ch : result.toCharArray()) {
						--count[ch - '0'];
					}

					for (int c : count) {
						if (c != 0) {
							isOk = false;
							break;
						}
					}

					if (isOk) {
						isOk = Integer.parseInt(result) % 7 == 0;
					}
				}

				if (!isOk) {
					System.out.println("ERROR for string = " + s + ", got = " + result + ", possible = " + t);
					System.exit(1);
				}
			}
		} else {
			String result = solveForString(in.readLine());
			out.writeln(result);
		}
	}

	private final String dfs0(final int pos, final boolean[] used, final int[] positions, final String s) {

		if (pos == used.length) {

			StringBuilder sb = new StringBuilder();

			for (int i = 0; i < used.length; ++i) {
				sb.append(s.charAt(positions[i]));
			}

			if (sb.charAt(0) == '0') {
				return null;
			}

			return Integer.valueOf(sb.toString()) % 7 == 0 ? sb.toString() : null;
		}

		String t;

		for (int i = 0; i < used.length; ++i) {
			if (used[i]) {
				continue;
			}

			positions[pos] = i;
			used[i] = true;

			if ((t = dfs0(pos + 1, used, positions, s)) != null) {
				return t;
			}

			used[i] = false;
		}

		return null;
	}

	private final String solveForString(final String string) {
		final char[] s = new StringBuilder(string).reverse().toString().toCharArray();
		final int[] nums = new int[s.length];
		for (int i = 0; i < s.length; ++i) {
			nums[i] = s[i] - '0';
		}

		final int[] pos = new int[4];
		for (int i = 0; i < nums.length; ++i) {
			if (nums[i] == 1) {
				pos[0] = i;
			}
			if (nums[i] == 6) {
				pos[1] = i;
			}
			if (nums[i] == 8) {
				pos[2] = i;
			}
			if (nums[i] == 9) {
				pos[3] = i;
			}
		}

		final int[] target = new int[] { 1, 6, 8, 9 };

		for (int i = nums.length - 1, j = 0; j < target.length; ++j, --i) {

			for (int q = nums.length - 1; q >= 0; --q) {
				if (nums[q] == target[j]) {

					int t;

					t = nums[q];
					nums[q] = nums[i];
					nums[i] = t;

					pos[j] = i;
					break;
				}
			}
		}

		pow[0] = 1;
		for (int i = 0; i < nums.length - 4; ++i) {
			pow[0] = (pow[0] * 10) % 7;
		}

		pow[1] = (pow[0] * 10) % 7;
		pow[2] = (pow[1] * 10) % 7;
		pow[3] = (pow[2] * 10) % 7;

		modButLastFour = 0;
		for (int i = nums.length - 1; i >= 0; --i) {
			modButLastFour = (modButLastFour * 10 + nums[i]) % 7;
		}

		modButLastFour -= nums[nums.length - 4] * pow[0];
		modButLastFour -= nums[nums.length - 3] * pow[1];
		modButLastFour -= nums[nums.length - 2] * pow[2];
		modButLastFour -= nums[nums.length - 1] * pow[3];

		modButLastFour = (modButLastFour % 7 + 7) % 7;

		boolean isOk = dfs(0, pos, new int[4], new boolean[4], nums);

		StringBuilder result = new StringBuilder();

		if (isOk) {
			for (int i = nums.length - 1; i >= 0; --i) {
				result.append((char) ('0' + nums[i]));
			}
		} else {
			result.append("0");
		}

		return result.toString();
	}

	int modButLastFour = 0;
	int powTenModButLastFour = 0;
	int pow[] = new int[4];

	private final boolean dfs(final int pos, final int[] positions, final int[] newPositions, final boolean[] used, final int[] nums) {

		if (pos == 4) {

			nums[positions[newPositions[0]]] = 1;
			nums[positions[newPositions[1]]] = 6;
			nums[positions[newPositions[2]]] = 8;
			nums[positions[newPositions[3]]] = 9;

			if (isOk(nums)) {
				return true;
			}

			nums[positions[0]] = 1;
			nums[positions[1]] = 6;
			nums[positions[2]] = 8;
			nums[positions[3]] = 9;

			return false;
		}
		for (int i = 0; i < positions.length; ++i) {
			if (used[i]) {
				continue;
			}
			used[i] = true;
			newPositions[pos] = i;
			if (dfs(pos + 1, positions, newPositions, used, nums)) {
				return true;
			}
			used[i] = false;
		}

		return false;
	}

	private final boolean isOk(int[] nums) {

		int diff = modButLastFour;

		diff += nums[nums.length - 4] * pow[0];
		diff += nums[nums.length - 3] * pow[1];
		diff += nums[nums.length - 2] * pow[2];
		diff += nums[nums.length - 1] * pow[3];

		return diff % 7 == 0;
	}

	private static final class InputReader {

		private static final byte ZERO = '0';
		private static final byte NINE = '9';

		private static final int BUFFER_SIZE = 1 << 17;

		private final BufferedInputStream in;

		private byte[] buffer = new byte[BUFFER_SIZE + 1];
		private int offset = buffer.length;

		private InputReader(final InputStream in) {

			this.in = (in instanceof BufferedInputStream) ? ((BufferedInputStream) in) : (new BufferedInputStream(in));
		}

		public int nextInt() throws Exception {

			int result = 0;

			int position = this.offset;

			while (position < BUFFER_SIZE && (buffer[position] < ZERO || buffer[position] > NINE)) {

				++position;
			}

			if (position >= BUFFER_SIZE) {

				System.arraycopy(buffer, offset, buffer, 0, position - offset);
				final int bytesRead = in.read(buffer, position - offset, BUFFER_SIZE - position + offset);
				buffer[position - offset + (bytesRead == -1 ? 0 : bytesRead)] = 0;
				offset = 0;

				return nextInt();
			}

			offset = position;

			while (position < BUFFER_SIZE && buffer[position] >= ZERO && buffer[position] <= NINE) {

				result = result * 10 + buffer[position] - ZERO;
				++position;
			}

			if (position >= BUFFER_SIZE) {

				System.arraycopy(buffer, offset, buffer, 0, position - offset);
				final int bytesRead = in.read(buffer, position - offset, BUFFER_SIZE - position + offset);
				buffer[position - offset + (bytesRead == -1 ? 0 : bytesRead)] = 0;
				offset = 0;

				return nextInt();
			}

			offset = position;

			return result;
		}

		public long nextLong() throws Exception {

			long result = 0;

			int position = this.offset;

			while (position < BUFFER_SIZE && (buffer[position] < ZERO || buffer[position] > NINE)) {

				++position;
			}

			if (position >= BUFFER_SIZE) {

				System.arraycopy(buffer, offset, buffer, 0, position - offset);
				final int bytesRead = in.read(buffer, position - offset, BUFFER_SIZE - position + offset);
				buffer[position - offset + (bytesRead == -1 ? 0 : bytesRead)] = 0;
				offset = 0;

				return nextLong();
			}

			offset = position;

			while (position < BUFFER_SIZE && buffer[position] >= ZERO && buffer[position] <= NINE) {

				result *= 10;
				result += buffer[position] - ZERO;
				++position;
			}

			if (position >= BUFFER_SIZE) {

				System.arraycopy(buffer, offset, buffer, 0, position - offset);
				final int bytesRead = in.read(buffer, position - offset, BUFFER_SIZE - position + offset);
				buffer[position - offset + (bytesRead == -1 ? 0 : bytesRead)] = 0;
				offset = 0;

				return nextLong();
			}

			offset = position;

			return result;
		}

		public String next() throws Exception {

			int position = this.offset;

			while (position < BUFFER_SIZE && Character.isWhitespace(buffer[position])) {

				++position;
			}

			if (position >= BUFFER_SIZE) {

				System.arraycopy(buffer, offset, buffer, 0, position - offset);
				final int bytesRead = in.read(buffer, position - offset, BUFFER_SIZE - position + offset);
				buffer[position - offset + (bytesRead == -1 ? 0 : bytesRead)] = 0;
				offset = 0;

				return next();
			}

			offset = position;

			while (position < BUFFER_SIZE && !Character.isWhitespace(buffer[position])) {
				++position;
			}

			if (position >= BUFFER_SIZE) {

				System.arraycopy(buffer, offset, buffer, 0, position - offset);
				final int bytesRead = in.read(buffer, position - offset, BUFFER_SIZE - position + offset);
				buffer[position - offset + (bytesRead == -1 ? 0 : bytesRead)] = 0;
				offset = 0;

				return next();
			}

			final String result = new String(buffer, offset, position - offset);
			offset = position;

			return result;
		}

	}

	private static final class OutputWriter {

		private static final String NEW_LINE = String.format("%n");

		private final Writer output;
		private final StringBuilder buffer = new StringBuilder(2 << 20);

		public OutputWriter(final Writer output) {

			this.output = output;
		}

		public void write(final int i) {

			buffer.append(i);
		}

		public void write(final String s) {

			buffer.append(s);
		}

		public void writeln(final String s) {

			buffer.append(s);
			buffer.append(NEW_LINE);
		}

		public void writeln(final long l) {

			buffer.append(l);
			buffer.append(NEW_LINE);
		}

		public void writeln(final int i) {

			buffer.append(i);
			buffer.append(NEW_LINE);
		}

		public void close() throws Exception {

			output.write(buffer.toString());
			output.flush();
			output.close();
		}
	}
}
