#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30);
const int N = int(1e5) + 500;
int n, sum, a[N];
bool u[N];
int solve() {
  cin >> n;
  sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + n);
  if (a[0] != 0) {
    cout << "-1";
    return 0;
  }
  if (!(sum % 3)) {
    bool have = 0;
    for (int i = 0; i < n; i++)
      if (a[i]) have = 1;
    if (have) {
      for (int i = n - 1; i >= 0; i--) cout << a[i];
    } else
      cout << "0";
  }
  if (sum % 3 == 1) {
    bool have = 0;
    int count = 0;
    for (int i = 0; i < n; i++) u[i] = 0;
    bool was = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] % 3 == 1) {
        u[i] = 1;
        was = 1;
        break;
      }
    }
    if (!was) {
      for (int i = 0; i < n; i++) {
        if (a[i] % 3 == 2) {
          u[i] = 1;
          count++;
          if (count == 2) break;
        }
      }
    }
    for (int i = 0; i < n; i++)
      if (!u[i] && a[i]) have = 1;
    if (have) {
      for (int i = n - 1; i >= 0; i--)
        if (!u[i]) cout << a[i];
    } else
      cout << "0";
  }
  if (sum % 3 == 2) {
    bool have = 0;
    int count = 0;
    for (int i = 0; i < n; i++) u[i] = 0;
    bool was = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] % 3 == 2) {
        u[i] = 1;
        was = 1;
        break;
      }
    }
    if (!was) {
      for (int i = 0; i < n; i++) {
        if (a[i] % 3 == 1) {
          u[i] = 1;
          count++;
          if (count == 2) break;
        }
      }
    }
    for (int i = 0; i < n; i++)
      if (!u[i] && a[i]) have = 1;
    if (have) {
      for (int i = n - 1; i >= 0; i--)
        if (!u[i]) cout << a[i];
    } else
      cout << "0";
  }
  return 0;
}
int main() {
  solve();
  return 0;
}
