#include <bits/stdc++.h>
const double eps = 1e-10;
using namespace std;
int n, m, q, a, b, k;
int so;
int allin, games;
const int N = (1111111);
int in[N];
int answ;
void cut(int m, int k) {
  for (int i = 0; i < n; i++) {
    if (k <= 0) break;
    if (in[i] != -1 && in[i] % 3 == m) {
      in[i] = -1;
      k--;
    }
  }
}
int main() {
  scanf("%d", &n);
  bool can = 0;
  long long answr = 1;
  long long ss = 0;
  int one = 0, two = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &in[i]);
    if (in[i] == 0) {
      can = 1;
    }
    if (in[i] % 3 == 1) one++;
    if (in[i] % 3 == 2) two++;
    ss += in[i];
  }
  if (!can) {
    printf("-1\n");
    return 0;
  }
  sort(in, in + n);
  if (ss % 3 == 1) {
    if (one > 0) {
      cut(1, 1);
    } else if (two >= 2) {
      cut(2, 2);
    }
  } else if (ss % 3 == 2) {
    if (two > 0) {
      cut(2, 1);
    } else if (one > 1) {
      cut(1, 2);
    }
  }
  bool fl = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (in[i] != -1) {
      printf("%d", in[i]);
      if (fl == 0 && in[i] == 0) {
        fl = 1;
        break;
      }
      fl = 1;
    }
  }
  return 0;
}
