Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?

Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.

Input

The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.

Output

In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.

Examples

Input

4
5 0 5 0


Output

0


Input

11
5 5 5 5 5 5 5 5 0 5 5


Output

5555555550

Note

In the first test you can make only one number that is a multiple of 90 — 0.

In the second test you can make number 5555555550, it is a multiple of 90.
import java.io.*;
import java.util.*;

public class A
{
    static int n;
    static int[] arr;
    static char[] s;
    public static void main(String[] args) throws IOException
    {
        Flash f = new Flash();
        out = new PrintWriter(System.out);
        
        int T = 1; //f.ni();
        for(int tc = 1; tc <= T; tc++){
            n = f.ni(); arr = f.arr(n); sop(fn());
        }
        
        out.flush(); out.close();
    }
    
    static String fn()
    {
        int sum = 0, cnt = 0;
        for(int a : arr){
            sum += a;
            if(a == 5) cnt++;
        }
        
        int cnt0 = n-cnt;
        
        while(sum % 9 != 0){
            if(cnt > 0){
                cnt -= 1;
                sum -= 5;
            }
            
            else return "0";
        }
        
        if(cnt == 0 && cnt0 == 0) return "-1";
        if(cnt == 0 && cnt0 >= 1) return "0";
        if(cnt >= 1 && cnt0 == 0) return "-1";
        
        StringBuilder ans = new StringBuilder();
        for(int i = 1; i <= cnt; i++) ans.append("5");
        for(int i = 1; i <= cnt0; i++) ans.append("0");
        return ans.toString();
    }
    
    static PrintWriter out;
    static final long mod = (long)1e9+7;
    static final long inf = Long.MAX_VALUE;
    static final int _inf = Integer.MAX_VALUE;
    
    static void sort(int[] a){
        List<Integer> A = new ArrayList<>();
        for(int i : a) A.add(i);
        Collections.sort(A);
        for(int i = 0; i < A.size(); i++) a[i] = A.get(i);
    }
    
    static int swap(int itself, int dummy){
        return itself;
    }
    
    static void sop(Object o){ 
        out.println(o);
    }
    
    static void print(int[] a){
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < a.length; i++) sb.append(a[i] + " ");
        sop(sb);
    }
    
    static class Flash
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");
        
        String next(){
            while(!st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch(IOException e){
                    e.printStackTrace();
                }
            }
            
            return st.nextToken();
        }
        
        String ns(){
            String s = new String();
            try{
                s = br.readLine().trim();
            }catch(IOException e){
                e.printStackTrace();
            }
            
            return s;
        }
        
        char[] nc(){
            return ns().toCharArray();
        }
        
        int ni(){
            return Integer.parseInt(next());
        }
        
        int[] arr(int n){
            int[] a = new int[n];
            for(int i = 0; i < n; i++) a[i] = ni();
            return a;
        }

        long nl(){
            return Long.parseLong(next());
        }
        
        double nd(){
            return Double.parseDouble(next());
        }
    }
}