#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, r = 0, s = 0, l = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      r = r + 1;
    else {
      s = s + 1;
      l = l + a[i];
    }
  }
  if (r == 0) {
    cout << "-1" << endl;
    return 0;
  } else if (s < 9) {
    cout << "0" << endl;
    return 0;
  } else {
    for (int i = 0; i < (s - (s % 9)); i++) cout << "5";
    for (int i = 0; i < r; i++) cout << "0";
  }
}
