#include <bits/stdc++.h>
using namespace std;
int n, a[1010], sum, id;
bool z;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    if (!a[i]) z = true;
    sum += a[i];
    if (sum % 9 == 0) id = i;
  }
  if (!z) {
    printf("-1");
    return 0;
  }
  while (a[id] == 0 && id > 1) id--;
  for (int i = id; i >= 1; i--) printf("%d", a[i]);
  return 0;
}
