#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  int sm = 0;
  priority_queue<int, vector<int>, greater<int>> pq1;
  priority_queue<int, vector<int>, greater<int>> pq2;
  bool f = false;
  priority_queue<int> ans;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 0) f = true;
    if (a[i] % 3 == 0)
      ans.push(a[i]);
    else if (a[i] % 3 == 1)
      pq1.push(a[i]);
    else
      pq2.push(a[i]);
    sm += a[i];
  }
  if (!f) {
    cout << -1 << endl;
    return 0;
  }
  if (sm % 3 == 1) {
    if (pq1.size() != 0) {
      pq1.pop();
    } else {
      assert(pq2.size() >= 2);
      pq2.pop();
      pq2.pop();
    }
  } else if (sm % 3 == 2) {
    if (pq2.size() != 0) {
      pq2.pop();
    } else {
      assert(pq1.size() >= 2);
      pq1.pop();
      pq1.pop();
    }
  }
  while (!pq1.empty()) {
    ans.push(pq1.top());
    pq1.pop();
  }
  while (!pq2.empty()) {
    ans.push(pq2.top());
    pq2.pop();
  }
  if (ans.top() == 0) {
    cout << 0 << endl;
    return 0;
  }
  while (!ans.empty()) {
    cout << ans.top();
    ans.pop();
  }
  cout << endl;
}
