#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  long long int mc[6];
  mc[0] = mc[5] = 0;
  for (long long int i = 0, k = 0; i < n; i++) {
    cin >> k;
    mc[k] += 1;
  }
  if (mc[0] < 1)
    cout << -1;
  else if (mc[5] < 9)
    cout << 0;
  else {
    for (long long int i = 0; i < mc[5] / 9 * 9; i++) cout << 5;
    for (long long int i = 0; i < mc[0]; i++) cout << 0;
  }
  return 0;
}
