#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> vec(n);
  long long zCount = 0, fCount = 0;
  for (long long i = 0; i < n; i++) {
    cin >> vec[i];
    if (vec[i] == 0)
      zCount++;
    else
      fCount++;
  }
  long long num = fCount / 9;
  if (zCount == 0) {
    cout << -1 << endl;
    return 0;
  } else if (num == 0) {
    cout << 0 << endl;
    return 0;
  } else {
    for (long long i = 0; i < 9 * num; i++) cout << 5;
    for (long long i = 0; i < zCount; i++) cout << 0;
    cout << endl;
  }
}
