#include <bits/stdc++.h>
using namespace std;
vector<int> v, dat[2];
int n;
void rem(int s, int cnt) {
  vector<int> ans;
  cnt--;
  int index = 0;
  for (int i = 0; i < n; i++) {
    if (index <= cnt && i == dat[s][index]) {
      index++;
    } else
      ans.push_back(v[i]);
  }
  reverse((ans).begin(), (ans).end());
  int c = 0;
  for (int i = 0; i < ans.size(); i++)
    if (ans[i]) c = 1;
  if (c)
    for (int i : ans) cout << i;
  else
    cout << 0;
  cout << '\n';
}
int main() {
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    sum += t;
    v.push_back(t);
  }
  sort((v).begin(), (v).end());
  for (int i = 0; i < n; i++) {
    if (v[i] && v[i] % 3 == 1) dat[0].push_back(i);
    if (v[i] && v[i] % 3 == 2) dat[1].push_back(i);
  }
  if (!(v[0] == 0 &&
        (sum % 3 == 0 ||
         (sum % 3 == 1 && (dat[0].size() || dat[1].size() >= 2)) ||
         (sum % 3 == 2 && (dat[0].size() >= 2 || dat[1].size()))))) {
    cout << -1 << '\n';
    return 0;
  }
  if (sum % 3 == 0)
    rem(0, 0);
  else if (sum % 3 == 1 && dat[0].size())
    rem(0, 1);
  else if (sum % 3 == 1)
    rem(1, 2);
  else if (sum % 3 == 2 && dat[1].size())
    rem(1, 1);
  else
    rem(0, 2);
}
