#include <bits/stdc++.h>
using namespace std;
void Q_Q() {
  ios::sync_with_stdio(0);
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
}
vector<vector<int>> v;
int main() {
  Q_Q();
  int n;
  cin >> n;
  long long int sum = 0;
  v.resize(3);
  bool found = 0;
  long long int zeros = 0;
  while (n--) {
    int x;
    cin >> x;
    if (x == 0) {
      found = 1;
      zeros++;
    } else if (x % 3 == 0) {
      v[0].push_back(x);
    } else if (x % 3 == 1) {
      v[1].push_back(x);
    } else {
      v[2].push_back(x);
    }
    sum += x;
  }
  if (!found) return cout << -1, 0;
  vector<int> ans;
  if (sum % 3 == 1) {
    if (v[1].size()) {
      sort(v[1].rbegin(), v[1].rend());
      v[1].pop_back();
    } else if (v[2].size() >= 2) {
      sort(v[2].rbegin(), v[2].rend());
      v[2].pop_back();
      v[2].pop_back();
    }
  } else if (sum % 3 == 2) {
    if (v[2].size()) {
      sort(v[2].rbegin(), v[2].rend());
      v[2].pop_back();
    } else if (v[1].size() >= 2) {
      sort(v[1].rbegin(), v[1].rend());
      v[1].pop_back();
      v[1].pop_back();
    }
  }
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < v[i].size(); j++) ans.push_back(v[i][j]);
  }
  sort(ans.rbegin(), ans.rend());
  for (int i = 0; i < ans.size(); i++) cout << ans[i];
  if (ans.size()) {
    while (zeros--) cout << 0;
  } else
    cout << 0;
  return 0;
}
