#include <bits/stdc++.h>
int a[10];
int sm() {
  int gg = 0;
  for (int i = 1; i <= 9; i++) gg += a[i] * i;
  return gg;
}
int main() {
  int n, bf;
  scanf("%i", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%i", &bf);
    a[bf]++;
  }
  if (a[0] == 0) {
    printf("-1");
    exit(0);
  }
  int i, gg = 0, flg = 1;
  while ((sm() % 3) != 0) {
    if ((sm() % 3) == 1)
      i = 1;
    else
      i = 2;
    if (flg != 1) {
      i = 3 - i;
      flg = 0;
    }
    for (i; i <= 9; i += 3)
      if (a[i] != 0) {
        a[i]--;
        break;
      }
    flg++;
    gg++;
    if (gg == 10) {
      printf("-1");
      exit(0);
    }
  }
  if (sm() == 0) a[0] = 1;
  for (int i = 9; i >= 0; i--)
    if (a[i] != 0)
      for (int j = 1; j <= a[i]; j++) printf("%i", i);
  return 0;
}
