#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = 10 * x + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  int n = read(), five = 0, zero = 0;
  for (int i = 1; i <= n; i++) {
    int k = read();
    if (k == 5) {
      five++;
    } else {
      zero++;
    }
  }
  if (!zero) {
    printf("-1");
  } else {
    for (int i = 1; i <= (five / 9) * 9; i++) {
      printf("5");
    }
    if (!(five / 9)) {
      printf("0");
      return 0;
    }
    for (int i = 1; i <= zero; i++) {
      printf("0");
    }
  }
  return 0;
}
