#include <bits/stdc++.h>
using namespace std;
int f[100100];
int n;
bool cmp(int a, int b) { return a > b; }
int main() {
  int i, j, fa, fb, fc;
  int sum, qian;
  while (scanf("%d", &n) != EOF) {
    sum = 0;
    qian = 0;
    fa = -1;
    fb = -1;
    fc = -1;
    for (i = 0; i < n; i++) {
      scanf("%d", &f[i]);
      sum += f[i];
    }
    sort(f, f + n, cmp);
    if (f[n - 1] != 0) {
      printf("-1\n");
      continue;
    } else {
      if (sum % 3 == 0) {
        for (i = 0; i < n; i++) {
          if (qian == 0 && f[i] == 0)
            continue;
          else
            qian = 1;
          printf("%d", f[i]);
        }
        if (qian == 0)
          printf("0\n");
        else
          printf("\n");
        continue;
      }
      if (sum % 3 == 1) {
        for (i = n - 1; i >= 0; i--) {
          if (f[i] % 3 == 2 && fa == -1) {
            fa = i;
            continue;
          }
          if (f[i] % 3 == 2 && fa != -1 && fb == -1) {
            fb = i;
            continue;
          }
          if (f[i] % 3 == 1 && fc == -1) {
            fc = i;
            continue;
          }
        }
      }
      if (sum % 3 == 2) {
        for (i = n - 1; i >= 0; i--) {
          if (f[i] % 3 == 1 && fa == -1) {
            fa = i;
            continue;
          }
          if (f[i] % 3 == 1 && fa != -1 && fb == -1) {
            fb = i;
            continue;
          }
          if (f[i] % 3 == 2 && fc == -1) {
            fc = i;
            continue;
          }
        }
      }
      if (fc != -1) {
        for (i = 0; i < n; i++) {
          if (qian == 0 && f[i] == 0 || i == fc)
            continue;
          else
            qian = 1;
          if (i != fc) printf("%d", f[i]);
        }
        if (qian == 0)
          printf("0\n");
        else
          printf("\n");
        continue;
      }
      if (fb != -1 && fa != -1) {
        for (i = 0; i < n; i++) {
          if ((qian == 0 && f[i] == 0) || i == fa || i == fb)
            continue;
          else
            qian = 1;
          if (i != fa && i != fb) printf("%d", f[i]);
        }
        if (qian == 0)
          printf("0\n");
        else
          printf("\n");
        continue;
      }
    }
    printf("-1\n");
  }
  return 0;
}
