#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int nums[2] = {0};
  cin >> n;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == 0)
      nums[0]++;
    else
      nums[1]++;
  }
  int fives = nums[1] / 9;
  if (fives > 0 && nums[0] > 0) {
    for (int i = 0; i < fives * 9; i++) cout << 5;
    for (int i = 0; i < nums[0]; i++) cout << 0;
  } else {
    cout << (nums[0] > 0 ? 0 : -1);
  }
  cout << endl;
}
