#include <bits/stdc++.h>
int main() {
  long set[10];
  long mod[2];
  int n, c;
  int i, j;
  int mod_val, rev_mod_val;
  int first;
  for (i = 0; i < 10; i++) set[i] = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &c);
    set[c]++;
  }
  if (set[0] == 0) {
    printf("-1");
  } else {
    if (set[0] == n) {
      printf("0");
    } else {
      mod[0] = set[1] + set[4] + set[7];
      mod[1] = set[2] + set[5] + set[8];
      mod_val = (mod[0] + mod[1] * 2) % 3;
      if (mod_val != 0) {
        if (mod[mod_val - 1] > 0) {
          for (i = mod_val; i < 10; i += 3) {
            if (set[i] > 0) {
              set[i]--;
              mod_val = 0;
              break;
            }
          }
        } else {
          rev_mod_val = (mod_val == 1) ? 2 : 1;
          c = 2;
          for (i = rev_mod_val; i < 10; i += 3) {
            if (set[i] >= c) {
              set[i] -= c;
              c = 0;
            } else {
              c -= set[i];
              set[i] = 0;
            }
            if (c == 0) {
              mod_val = 0;
              break;
            }
          }
        }
      }
      if (mod_val == 0) {
        first = 0;
        for (i = 9; i >= 0; i--) {
          if (i == 0 && first == 0) {
            printf("0");
          } else {
            for (j = 0; j < set[i]; j++) printf("%d", i);
          }
          if (set[i] > 0) first = 1;
        }
      } else {
        printf("-1");
      }
    }
  }
  printf("\n");
  return 0;
}
