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.awt.Point;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

import static java.lang.Math.*;

public class Main {

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	void init() throws FileNotFoundException {
		if (ONLINE_JUDGE) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	long readLong() throws IOException {
		return Long.parseLong(readString());
	}

	double readDouble() throws IOException {
		return Double.parseDouble(readString());
	}

	public static void main(String[] args) {
		new Main().run();
		// Sworn to fight and die
	}

	public static void mergeSort(int[] a) {
		mergeSort(a, 0, a.length - 1);
	}

	private static void mergeSort(int[] a, int levtIndex, int rightIndex) {
		final int MAGIC_VALUE = 50;
		if (levtIndex < rightIndex) {
			if (rightIndex - levtIndex <= MAGIC_VALUE) {
				insertionSort(a, levtIndex, rightIndex);
			} else {
				int middleIndex = (levtIndex + rightIndex) / 2;
				mergeSort(a, levtIndex, middleIndex);
				mergeSort(a, middleIndex + 1, rightIndex);
				merge(a, levtIndex, middleIndex, rightIndex);
			}
		}
	}

	private static void merge(int[] a, int levtIndex, int middleIndex,
			int rightIndex) {
		int length1 = middleIndex - levtIndex + 1;
		int length2 = rightIndex - middleIndex;
		int[] levtArray = new int[length1];
		int[] rightArray = new int[length2];
		System.arraycopy(a, levtIndex, levtArray, 0, length1);
		System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
		for (int k = levtIndex, i = 0, j = 0; k <= rightIndex; k++) {
			if (i == length1) {
				a[k] = rightArray[j++];
			} else if (j == length2) {
				a[k] = levtArray[i++];
			} else {
				a[k] = levtArray[i] <= rightArray[j] ? levtArray[i++]
						: rightArray[j++];
			}
		}
	}

	private static void insertionSort(int[] a, int levtIndex, int rightIndex) {
		for (int i = levtIndex + 1; i <= rightIndex; i++) {
			int current = a[i];
			int j = i - 1;
			while (j >= levtIndex && a[j] > current) {
				a[j + 1] = a[j];
				j--;
			}
			a[j + 1] = current;
		}
	}

	public void run() {
		try {
			long t1 = System.currentTimeMillis();
			init();
			solve();
			out.close();
			long t2 = System.currentTimeMillis();
			System.err.println("Time = " + (t2 - t1));
		} catch (Exception e) {
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	class LOL implements Comparable<LOL> {
		int k;
		int r;

		@Override
		public int compareTo(LOL o) {

			return r - o.r; // ---->
			// return o.x - x; // <----
			// return o.y-y;
		}

		public LOL(int xx, int yy, int kk) {
			this.r = xx * xx + yy * yy;
			this.k = kk;
		}

	}

	public long gcd(long a, long b) {
		if (a % b == 0)
			return b;
		else
			return gcd(b, a % b);
	}

	public int gcd(int a, int b) {
		if (a % b == 0)
			return b;
		else
			return gcd(b, a % b);
	}

	public int d7(int[] a) {
		int len = a.length;
		int r = len % 3;
		int m = 1;
		int ans = 0;
		int ost = 0;
		while (len > r) {
			ans += m * (100 * a[len - 3] + 10 * a[len - 2] + a[len - 1]);
			m = -m;
			len -= 3;
		}
		if (r == 1)
			ost += a[0];
		if (r == 2)
			ost = 10 * a[0] + a[1];
		ans += ost * m;
		ans%=7;
		return ((ans+7));
	}

	public void solve() throws IOException {
		
		String s = readString();
		char[] c = s.toCharArray();
		int[] a = new int[c.length];
		int[] num = new int[10];
		int ans = 0;

		for (int i = 0; i < c.length; i++) {
			a[i] = c[i] - 48;
			num[a[i]]++;
		}
		int numost = c.length - 4 - num[0];
		int[] ost = new int[numost + 1];
		int k = 1;
		ost[0] = 0;
		for (int i = 0; i < a.length; i++) 
			if (num[a[i]]>1 && a[i] !=0) {
			
				ost[k++] = a[i];
				num[a[i]]--;
				out.print(a[i]);
			}
		 
		if(num[2]>0) {
			ost[k] = 2; 
			out.print(ost[k++]);
		}
		if(num[3]>0) {
			ost[k] = 3; 
			out.print(ost[k++]);
		}
		if(num[4]>0) {
			ost[k] = 4; 
			out.print(ost[k++]);
		}
		if(num[5]>0) {
			ost[k] = 5; 
			out.print(ost[k++]);
		}
		if(num[7]>0) {
			ost[k] = 7; 
			out.print(ost[k++]);
		}
		
		switch (d7(ost)%7) {
		case 0:
			ans = 1869; break;
		case 1:
			ans = 6198; break;
		case 2:
			ans = 1896; break;
		case 3:
			ans = 1689; break;
		case 4:
			ans = 1986; break;
		case 5:
			ans = 1968; break;
		case 6:
			ans = 1698; break;
		}
		
		out.print(ans);
		for(int i=0; i<num[0]; i++) out.print("0");

	}
}