#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
vector<vector<int>> dp;
int f(int i, int p) {
  if (i >= n) {
    if (p % 3 == 0) {
      return 0;
    }
    return INT_MIN;
  }
  auto& ret = dp[i][p];
  if (~ret) {
    return ret;
  }
  int p1 = f(i + 1, p);
  int p2 = 1 + f(i + 1, (p + a[i]) % 3);
  return ret = max(p1, p2);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  bool zero = false;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    zero |= a[i] == 0;
  }
  if (!zero) {
    cout << -1 << '\n';
    exit(0);
  }
  sort(a.rbegin(), a.rend());
  dp.assign(n + 2, vector<int>(3, -1));
  int p = 0;
  int m = f(0, 0);
  string s = "";
  for (int i = 0; i < n; i++) {
    int newP = (p + a[i]) % 3;
    if (dp[i + 1][newP] == m - 1) {
      s += a[i] + '0';
      m -= 1;
      p = newP;
    }
  }
  s += '0';
  while (s.front() == '0' and (int) s.size() > 1) s.pop_back();
  cout << s << '\n';
}
