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.util.Scanner;


public class main {

	public static void main(String[] args) {
		DivisibleBySeven.run();
	}

}

class DivisibleBySeven {
	private static String[] table;
	
	public static void run() {
		init_table ();
		String input = get_input();
		String output = get_output(input);
		System.out.println(output);
	}
	
	private static void init_table () {
		table = new String[7];
		table[0] = "1869";
		table[1] = "6819";
		table[2] = "1689";
		table[3] = "6891";
		table[4] = "1698";
		table[5] = "8916";
		table[6] = "1896";
	}
	
	private static String get_input() {
		Scanner reader = new Scanner (System.in);
		String input = reader.nextLine();
		reader.close();
		return input;
	}
	
	private static String get_output(String input) {
		String inst_input = instrument_input (input);
		Divisor divisor = new Divisor (inst_input);
		int remainder = divisor.get_remainder();
		int neg_remainder = (7 - remainder) % 7;
		
		int power = (input.length() - 4) % 6;
		int multiplier = 1;
		for (int i = 0; i < power; i++)
			multiplier = multiplier * 3;
		multiplier = multiplier % 7;
		
		int prefix_remainder = neg_remainder;
		while (multiplier != 1) {
			multiplier = (multiplier * 3) % 7;
			prefix_remainder = (prefix_remainder * 3) % 7;
		}
		
		String output = table[prefix_remainder].concat(inst_input.substring(4));
		return output;
	}
	
	private static String instrument_input (String input) {
		int cnt = 0;
		boolean[] is_achieved = new boolean[10];
		char num_char;
		int num;
		char[] input_array = input.toCharArray();
		
		for (int i = 0; i < input.length(); i++) {
			num_char = input_array[i];
			if (num_char == '1' || num_char == '6' || num_char == '8' || num_char == '9') {
				num = Character.getNumericValue(num_char);
				if (!is_achieved[num]) {
					input_array[i] = input_array[cnt];
					input_array[cnt] = '0';
					cnt++;
					is_achieved[num] = true;
				}
			}
		}
		return new String(input_array);
	}
}

class Divisor {
	private String input;
	private int buf[];
	private int idx, bufValue;
	private boolean is_positive;
	private int len, start, end;
	private int remainder;
	
	public Divisor (String input) {
		this.input = input;
		buf = new int[3];
		len = input.length();
		start = 0; end = len - 1;
		remainder = 0;
		is_positive = false;
	}
	
	public int get_remainder () {
		for (int i = end; i >= start; i--) {
			idx = (end - i) % 3;
			if (idx == 0) {
				flush_buf ();
			}
			buf[idx++] = Character.getNumericValue(input.charAt(i));
		}
		flush_buf ();
		return remainder;
	}
	
	private void flush_buf () {
		bufValue = buf[2] * 100 + buf[1] * 10 + buf[0];
		bufValue = is_positive ? bufValue : (-1) * bufValue;
		remainder = (remainder + bufValue) % 7;
		is_positive = !is_positive;
		buf[0] = buf[1] = buf[2] = 0;
	}
}