#include <bits/stdc++.h>
const double EPS = 1e-9;
const int MOD = 1000003;
const int INF = 2000 * 1000 * 1000;
using namespace std;
int popcount(int n) {
  bitset<32> b(n);
  return b.count();
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) {
  int temp = gcd(a, b);
  return temp ? (a / temp * b) : 0;
}
template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
inline bool isInteger(const std::string& s) {
  if (s.empty() || ((!isdigit(s[0])) && (s[0] != '-') && (s[0] != '+')))
    return false;
  char* p;
  strtol(s.c_str(), &p, 10);
  return (*p == 0);
}
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> freq(10);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    freq[v[i]]++;
    sum += v[i];
  }
  if (freq[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  bool flag = 1;
  if (sum % 3 == 1) {
    for (int i = 1; i <= 7; i += 3)
      if (freq[i]) {
        freq[i]--;
        flag = 0;
        break;
      }
    if (flag)
      for (int i = 2; i <= 8; i += 3)
        for (int j = i; j <= 8; j += 3)
          if (freq[i] && freq[j]) {
            freq[i]--;
            if (freq[j]) {
              freq[j]--;
              flag = 0;
              break;
            } else
              freq[i]++;
          }
    if (flag) {
      cout << -1 << endl;
      return 0;
    }
  } else if (sum % 3 == 2) {
    flag = 1;
    for (int i = 2; i <= 8; i += 3)
      if (freq[i]) {
        freq[i]--;
        flag = 0;
        break;
      }
    if (flag)
      for (int i = 1; i <= 7; i += 3)
        for (int j = i; j <= 7; j += 3)
          if (freq[i] && freq[j]) {
            freq[i]--;
            if (freq[j]) {
              freq[j]--;
              flag = 0;
              break;
            } else
              freq[i]++;
          }
    if (flag) {
      cout << -1 << endl;
      return 0;
    }
  }
  flag = 1;
  for (int i = 9; i >= 0; i--) {
    if (freq[i] && i) flag = 0;
    if (i == 0 & flag) {
      cout << 0 << endl;
      return 0;
    } else
      while (freq[i]--) cout << i;
  }
  cout << endl;
}
