#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> A, B, C;
  int n, a, S = 0, flag = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    S += a;
    if (a == 0) flag = 1;
    if (a % 3 == 0)
      A.push_back(a);
    else if (a % 3 == 1)
      B.push_back(a);
    else
      C.push_back(a);
  }
  if (flag == 0) {
    cout << "-1";
    return 0;
  }
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  if (S % 3 == 1) {
    if (B.size() >= 1) {
      B[0] = -1;
    } else if (C.size() >= 2) {
      C[0] = -1;
      C[1] = -1;
    } else {
      B.clear();
      C.clear();
    }
  } else if (S % 3 == 2) {
    if (C.size() >= 1) {
      C[0] = -1;
    } else if (B.size() >= 2) {
      B[0] = -1;
      B[1] = -1;
    } else {
      B.clear();
      C.clear();
    }
  }
  for (int i = 0; i < B.size(); i++) {
    A.push_back(B[i]);
  }
  for (int i = 0; i < C.size(); i++) {
    A.push_back(C[i]);
  }
  sort(A.begin(), A.end());
  if (A[A.size() - 1] == 0) {
    cout << 0 << "\n";
    return 0;
  }
  for (int i = A.size() - 1; i >= 0; i--) {
    if (A[i] != -1) cout << A[i];
  }
  return 0;
}
