#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
int a[10];
int n;
void solve() {
  int f = 0, s = 0;
  memset(a, 0, sizeof(a));
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[x]++;
    s += x;
  }
  if (a[0] == 0) {
    cout << "-1\n";
    return;
  }
  if (s % 3 == 0) f = 1;
  if (f == 0) {
    int e = s % 3;
    if (e == 1) {
      for (int i = e; i < 10; i += 3) {
        if (a[i]) {
          a[i]--;
          f = 1;
          break;
        }
      }
    } else if (e == 2) {
      for (int i = 2; i < 10; i += 3) {
        if (a[i]) {
          a[i]--;
          f = 1;
          break;
        }
      }
    }
    if (f == 0) {
      int need = 2;
      if (e == 1) {
        for (int i = 2; i < 10; i += 3) {
          int x = min(need, a[i] % 3);
          need -= x;
          a[i] -= x;
        }
      } else {
        for (int i = 1; i < 10; i += 3) {
          int x = min(a[i] % 3, need);
          need -= x;
          a[i] -= x;
        }
      }
    }
  }
  bool ok = false;
  for (int i = 9; i >= 1; i--) {
    ok |= a[i] > 0;
  }
  if (!ok) {
    cout << "0";
    return;
  }
  for (int i = 9; i >= 0; i--) {
    for (int j = 0; j < a[i]; j++) cout << i;
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
