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