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 Main{
    public static void main(String args[]) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        
        boolean seen[] = new boolean[10];
        StringBuilder sb = new StringBuilder(s);
        //~ int zero = 0;
        int zero = 0;
        int res = 0;
        int ten = 1;
        StringBuilder out = new StringBuilder("");
        for(int i = 0 ; i < sb.length() ; i++){
            if(sb.charAt(i) == '1' && !seen[1]) { sb.deleteCharAt(i); i--; seen[1] = true; }
            else if(sb.charAt(i) == '6' && !seen[6]) { sb.deleteCharAt(i); i--; seen[6] = true;}
            else if(sb.charAt(i) == '8' && !seen[8]) { sb.deleteCharAt(i); i--; seen[8] = true; }
            else if(sb.charAt(i) == '9' && !seen[9]) { sb.deleteCharAt(i); i--; seen[9] = true; }
            else if(sb.charAt(i) == '0'){ 
                zero++;
            }
            else{
                ten = (ten*10) % 7;
                res = (res*10 + (sb.charAt(i) - '0')) % 7;
                out.append(sb.charAt(i));
                //~ System.out.print(sb.charAt(i));
            }
        }
        
        //~ System.out.println();
        //~ System.out.println("res "+res);
        //~ res = (7- res) % 7;
        //~ System.out.println("res "+res);
        int perm[] = {1, 6, 8, 9};
        String ans = "0";
        while(true){
            String perms = "";
            for(int i = 0 ; i < 4 ; i++) perms += perm[i];
            int num = Integer.parseInt(perms);
            num = (num * ten) % 7;
            num = (num + res) % 7;
            if(num == 0) {
                System.out.print(perms+""+out);
                break;
            }
            
            if(!nextPermutation(perm)) break;
        }
        
        for(int i = 0 ; i < zero ; i++){
            System.out.print(0);
        }
        System.out.println();
    }
    
    public static boolean nextPermutation(int ar[]){
        //find largest ar[i] < ar[i+1]
        int idx = 0;
        boolean found = false;
        for(int i = ar.length -2 ; i >= 0 ; i--){
            if(ar[i] < ar[i+1]){
                idx = i;
                found = true;
                break;
            }               
        }
        if(!found) return false;
        int swap = ar.length - 1;
        
        //find swappable item (first larger ar[swap] from end)
        while(ar[idx] > ar[swap]){
            swap--;
        }
        
        //swap idx and swap
        int tmp = ar[idx]; ar[idx] = ar[swap]; ar[swap] = tmp;
        
        //reverse from idx+1 behind
        
        for(int i = idx + 1, j = ar.length-1 ; i < (idx+1+ar.length)/2 ; j--, i++){
            tmp = ar[i]; ar[i] = ar[j]; ar[j] = tmp;
        }
        
        return true;
    }
}