#include <bits/stdc++.h>
int a[1005];
int main(void) {
  int n, i, j, p, count0 = 0, count5 = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 0) {
      count0++;
    }
  }
  count5 = n - count0;
  p = count5 / 9;
  if (count0) {
    if (p) {
      for (j = 0; j < p; j++) {
        printf("555555555");
      }
      for (j = 0; j < count0; j++) {
        printf("0");
      }
    } else {
      if (count0)
        printf("0");
      else
        printf("-1");
    }
  } else
    printf("-1");
  return 0;
}
