#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  int n, temp = 0;
  cin >> n;
  int noz = 0, nof = 0;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    v.push_back(t);
    if (t == 0)
      noz++;
    else
      nof++;
  }
  if (noz == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (nof < 9) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = nof;;) {
    if (i % 9 == 0) {
      temp = i;
      break;
    } else
      i--;
  }
  for (int i = 0; i < temp; i++) cout << 5;
  for (int i = 0; i < noz; i++) cout << 0;
  cout << endl;
  return 0;
}
