#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int sum = 0, count = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    if (a[i] == 0) {
      count++;
    }
  }
  if (count == 0) {
    cout << "-1";
    return 0;
  } else {
    if (sum < 45) {
      cout << "0";
      return 0;
    } else {
      while (1) {
        if (sum % 9 == 0) {
          int x = sum / 5;
          while (x--) {
            cout << "5";
          }
          break;
        } else {
          sum -= 5;
        }
      }
    }
  }
  for (int i = 0; i < count; i++) {
    cout << "0";
  }
  return 0;
}
