///package random_practiceQuestions;

import java.util.Arrays;
import java.util.Scanner;

public class B214 {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        s.nextLine();
        String[] l=s.nextLine().split(" ");
        int[] list=new int[l.length];
        int sum=0;
        for (int i=0;i<list.length;i++){
            list[i]=Integer.parseInt(l[i]);
            sum=sum+list[i];
        }
        Arrays.sort(list);
        if (list[0]!=0){
            System.out.println(-1);
        }
        else if (list[list.length-1]==0){
            System.out.println(0);
        }
        else{
            if (sum%3==0){
                for (int i=list.length-1;i>=0;i--){
                    System.out.print(list[i]);
                }
            }
            else{
                boolean check=false;
                int max1=-1;
                for (int i=0;i<list.length;i++){
                    if (list[i]%3==sum%3){
                        max1=i;
                        check=true;
                        break;
                    }
                }
                int max2=-1;
                int ind1=0;
                int count=0;
                for (int i=0;i<list.length;i++){
                    if (list[i]%3!=sum%3 && list[i]%3!=0){
                        count++;
                        if (count==1){
                            ind1=i;
                        }
                    }
                    if (count==2){
                        max2=i;
                        check=true;
                        break;
                    }
                }
                if (!check){
                    System.out.println(-1);
                }
                else{
                    String str="";
                    if (max1!=-1){
                        for (int i=list.length-1;i>=0;i--){
                            if (i!=max1){
                                str=str+list[i];
                            }
                        }
                    }
                    else {
                        for (int i=list.length-1;i>=0;i--){
                            if (i!=max2 && i!=ind1){
                                str=str+list[i];
                            }
                        }
                    }
                    if (str.charAt(0)=='0'){
                        System.out.println(0);
                    }
                    else{
                        System.out.println(str);
                    }
                }
            }
        }
    }
}
