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