#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = 1 << 29;
const int mod = 1000000007;
const int MAX_V = 1000 + 10;
const int MAX_M = 10000 + 10;
const int maxm = 1 + 5;
const int maxn = 50000 + 5;
int used[20];
int n;
int main() {
  scanf("%d", &n);
  int i, j, sum = 0, a;
  memset(used, 0, sizeof(used));
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    sum += a;
    used[a]++;
  }
  if (used[0] == 0)
    cout << -1 << endl;
  else {
    int flag = 0;
    if (sum % 3 == 1) {
      if (used[1] + used[4] + used[7]) {
        for (int i = 1; i <= 7; i += 3) {
          if (used[i]) {
            used[i]--, sum -= i;
            break;
          }
        }
      } else if (used[2] + used[5] + used[8] >= 2) {
        for (j = 1, i = 2; i <= 8; i += 3) {
          while (used[i] && j <= 2) used[i]--, sum -= i, j++;
        }
      }
    }
    if (sum % 3 == 2) {
      if (used[2] + used[5] + used[8]) {
        for (i = 2; i <= 8; i += 3)
          if (used[i]) {
            used[i]--, sum -= i;
            break;
          }
      } else if (used[1] + used[4] + used[7] >= 2) {
        for (j = 1, i = 1; i <= 7; i += 3)
          while (used[i] && j <= 2) used[i]--, sum -= i, j++;
      } else
        flag = 1;
    }
    if (!flag) {
      if (used[1] + used[2] + used[3] + used[4] + used[5] + used[6] + used[7] +
          used[8] + used[9]) {
        for (i = 9; i >= 0; i--)
          while (used[i]--) printf("%d", i);
        printf("\n");
      } else
        printf("0\n");
    } else
      printf("0\n");
  }
  return 0;
}
