#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int zeros = 0, fives = 0;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    if (temp == 0)
      zeros++;
    else
      fives++;
  }
  if (zeros == 0)
    cout << -1 << endl;
  else {
    if (fives < 9)
      cout << 0 << endl;
    else {
      for (int i = 0; i < (fives / 9) * 9; i++) cout << 5;
      for (int i = 0; i < zeros; i++) cout << 0;
      cout << endl;
    }
  }
}
