#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int mod(long long int x) { return x % 1000000007; }
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
class compare {
 public:
  bool operator()(long long int a, long long int b) { return a > b; }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  long long int sum = 0;
  vector<long long int> arr(n);
  long long int pos = -1;
  priority_queue<long long int, vector<long long int>, compare> pq0, pq1, pq2;
  for (long long int i = 0; i < n; ++i) {
    cin >> arr[i];
    sum += arr[i];
    if (arr[i] == 0) pos = i;
    if (arr[i] % 3 == 0)
      pq0.push(arr[i]);
    else if (arr[i] % 3 == 1)
      pq1.push(arr[i]);
    else
      pq2.push(arr[i]);
  }
  if (pos == -1) {
    cout << -1 << endl;
    return 0;
  }
  if (sum % 3 == 1) {
    while (!pq1.empty()) {
      if (sum % 3 == 0) break;
      sum -= 1;
      pq1.pop();
    }
    while (!pq2.empty()) {
      if (sum % 3 == 0) break;
      sum -= 2;
      pq2.pop();
    }
  } else if (sum % 3 == 2) {
    while (!pq2.empty()) {
      if (sum % 3 == 0) break;
      sum -= 2;
      pq2.pop();
    }
    while (!pq1.empty()) {
      if (sum % 3 == 0) break;
      sum -= 1;
      pq1.pop();
    }
  }
  if (sum % 3 != 0) {
    cout << -1 << endl;
    return 0;
  }
  priority_queue<long long int> pq;
  while (!pq1.empty()) {
    pq.push(pq1.top());
    pq1.pop();
  }
  while (!pq2.empty()) {
    pq.push(pq2.top());
    pq2.pop();
  }
  while (!pq0.empty()) {
    pq.push(pq0.top());
    pq0.pop();
  }
  if (pq.top() == 0) {
    cout << 0 << endl;
    return 0;
  }
  while (!pq.empty()) {
    cout << pq.top();
    pq.pop();
  }
  cout << endl;
}
