#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int K = 1e3 + 10;
const int MOD = 1e9 + 7;
int n;
int c0, c5, a;
int main() {
  cin >> n;
  for (int i = (0); i <= (n - 1); i++) {
    cin >> a;
    if (a == 0)
      c0++;
    else
      c5++;
  }
  if (c0 == 0) {
    cout << -1 << endl;
  } else {
    if (c5 < 9) {
      cout << 0 << endl;
    } else {
      for (int i = (1); i <= ((c5 / 9) * 9); i++) cout << 5;
      for (int i = (1); i <= (c0); i++) cout << 0;
      cout << endl;
    }
  }
  return 0;
}
