#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], count_zero = 0;
  vector<int> ans;
  vector<int> rem1;
  vector<int> rem2;
  long int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      count_zero++;
    }
    sum = sum + a[i];
    if (a[i] % 3 == 0) {
      ans.push_back(a[i]);
    } else if (a[i] % 3 == 1) {
      rem1.push_back(a[i]);
    } else {
      rem2.push_back(a[i]);
    }
  }
  if (count_zero == n) {
    cout << "0";
    return 0;
  } else if (count_zero == 0) {
    cout << "-1";
    return 0;
  }
  sort(ans.begin(), ans.end());
  sort(rem1.begin(), rem1.end());
  sort(rem2.begin(), rem2.end());
  reverse(ans.begin(), ans.end());
  reverse(rem1.begin(), rem1.end());
  reverse(rem2.begin(), rem2.end());
  if (sum % 3 == 1) {
    if (rem1.size() > 0) {
      rem1.erase(rem1.begin() + rem1.size() - 1);
    } else {
      rem2.erase(rem2.begin() + rem2.size() - 1);
      rem2.erase(rem2.begin() + rem2.size() - 1);
    }
  }
  if (sum % 3 == 2) {
    if (rem2.size() > 0) {
      rem2.erase(rem2.begin() + rem2.size() - 1);
    } else {
      rem1.erase(rem1.begin() + rem1.size() - 1);
      rem1.erase(rem1.begin() + rem1.size() - 1);
    }
  }
  vector<int> final_ans;
  for (int i = 0; i < rem1.size(); i++) {
    ans.push_back(rem1[i]);
  }
  for (int i = 0; i < rem2.size(); i++) {
    ans.push_back(rem2[i]);
  }
  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  if (ans.size() == count_zero) {
    cout << "0";
    return 0;
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i];
  }
  return 0;
}
