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.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {
    final static long MOD = 1000000007;
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = fs.nextInt();
        Integer a[] = fs.nextIntegerArray(n);
        Arrays.sort(a, Collections.reverseOrder());
        int fives = (int) Math.floor(Arrays.stream(a).filter(i -> i == 5).count()/9.0);
        int zeros = (int) Arrays.stream(a).filter(i -> i == 0).count();
        boolean contains0 = Arrays.stream(a).anyMatch(x -> x==0);
        boolean contains5 = Arrays.stream(a).anyMatch(x -> x==5);
        if(fives < 1) {
            if(contains0) {
                out.print(0);
            } else {
                out.print(-1);
            }
        }
        else {
            if(contains0) {
                IntStream.range(0,fives).forEach(i-> System.out.print("555555555"));
                IntStream.range(0,zeros).forEach(i-> System.out.print("0"));
            } else {
                out.print("-1");
            }
        }
        out.println();
        out.flush();
        out.close();
    }



    public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
        List<Map.Entry<K, V>> list = new ArrayList<>(map.entrySet());
        list.sort(Map.Entry.comparingByValue());
        Collections.reverse(list);

        Map<K, V> result = new LinkedHashMap<>();
        for (Map.Entry<K, V> entry : list) {
            System.out.println(entry.getKey()+" "+entry.getValue());
        }

        System.out.println(list.size());

        return result;
    }

    static boolean hasCommon(long a, long b) {
        char[] aa = (a+"").toCharArray();
        char[] bb = (b+"").toCharArray();
        return intersection(aa,bb);
    }

    public static boolean intersection(char[] a, char[] b) {
        for(int i = 0; i < a.length; i++) {
            for(int j = 0; j < b.length; j++) {
                if(a[i] == b[j])
                    return true;
            }
        }
        return false;
    }

    static long subsetAndSum(int[] set) {
        long total = 0;
        for (int k=1; k!=0; k<<=1) {
            int setBits = 0;
            for (int i : set) {
                if ((i&k)!=0) setBits++;
            }
            long subsets = (1L<<setBits)-1;
            total += (k * subsets) % MOD;
        }
        return total;
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                //br = new BufferedReader(new FileReader("Datatxt.txt"));
                st = new StringTokenizer("");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public String next() {
            if (st.hasMoreTokens())
                return st.nextToken();
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String line = "";
            try {
                line = br.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return line;
        }

        public Integer[] nextIntegerArray(int n) {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

        public char[] nextCharArray() {
            return nextLine().toCharArray();
        }
    }


}
class Node {
    int ind;
    int val;

    public Node(int ind, int val) {
        this.ind = ind;
        this.val = val;
    }

    public int getInd() {
        return ind;
    }

    public void setInd(int ind) {
        this.ind = ind;
    }

    public int getVal() {
        return val;
    }

    public void setVal(int val) {
        this.val = val;
    }
}