#include <bits/stdc++.h>
int a[11];
int main() {
  a[1] = 0;
  a[2] = 0;
  a[3] = 0;
  a[4] = 0;
  a[5] = 0;
  a[6] = 0;
  a[7] = 0;
  a[8] = 0;
  a[9] = 0;
  a[0] = 0;
  int i, j, k, n, percent1, percent2;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &j);
    a[j]++;
  }
  percent2 = a[2] + a[5] + a[8];
  percent1 = a[1] + a[4] + a[7];
  int flag = 0;
  if (((percent2 * 2 + percent1) % 3) == 0) {
    flag = 1;
  } else if (((percent2 * 2 + percent1) % 3) == 1) {
    if (a[1] != 0) {
      a[1] -= 1;
      flag = 1;
    } else if (a[4] != 0) {
      a[4] -= 1;
      flag = 1;
    } else if (a[7] != 0) {
      a[7] -= 1;
      flag = 1;
    } else if (a[2] != 0) {
      if (a[2] > 1) {
        a[2] -= 2;
        flag = 1;
      } else if (a[5] != 0) {
        a[2] -= 1;
        a[5] -= 1;
        flag = 1;
      } else if (a[8] != 0) {
        a[2] -= 1;
        a[8] -= 1;
        flag = 1;
      }
    } else if (a[5] != 0) {
      if (a[5] > 1) {
        a[5] -= 2;
        flag = 1;
      } else if (a[8] != 0) {
        a[5] -= 1;
        a[8] -= 1;
        flag = 1;
      }
    } else if (a[8] > 1) {
      a[8] -= 2;
      flag = 1;
    }
  } else if (((percent2 * 2 + percent1) % 3) == 2) {
    if (a[2] != 0) {
      a[2] -= 1;
      flag = 1;
    } else if (a[5] != 0) {
      a[5] -= 1;
      flag = 1;
    } else if (a[8] != 0) {
      a[8] -= 1;
      flag = 1;
    } else if (a[1] != 0) {
      if (a[1] > 1) {
        a[1] -= 2;
        flag = 1;
      } else if (a[4] != 0) {
        a[1] -= 1;
        a[4] -= 1;
        flag = 1;
      } else if (a[7] != 0) {
        a[1] -= 1;
        a[7] -= 1;
        flag = 1;
      }
    } else if (a[4] != 0) {
      if (a[4] > 1) {
        a[4] -= 2;
        flag = 1;
      } else if (a[7] != 0) {
        a[4] -= 1;
        a[7] -= 1;
        flag = 1;
      }
    } else if (a[7] > 1) {
      a[7] -= 2;
      flag = 1;
    }
  }
  int sum = 0;
  if (a[0] == 0)
    printf("-1");
  else {
    if (flag == 1) {
      for (i = 9; i > 0; i--) {
        sum += a[i];
        for (j = 0; j < a[i]; j++) {
          printf("%d", i);
        }
      }
      if (sum > 0) {
        for (j = 0; j < a[0]; j++) printf("0");
      } else
        printf("0");
    } else {
      if (a[0] != 0) {
        for (j = 0; j < a[9]; j++) printf("9");
        for (j = 0; j < a[6]; j++) printf("6");
        for (j = 0; j < a[3]; j++) printf("3");
        if (a[9] > 0 || a[6] > 0 || a[3] > 0) {
          for (j = 0; j < a[0]; j++) printf("0");
        } else {
          printf("0");
        }
      } else
        printf("-1");
    }
  }
  return 0;
}
