#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, count[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, c, max = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> c;
    count[c]++;
  }
  if (count[0] == 0) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i < 10; i++) max = max + i * count[i];
  if (max % 3 == 1) {
    if (count[1] > 0)
      count[1]--;
    else if (count[4] > 0)
      count[4]--;
    else if (count[7] > 0)
      count[7]--;
    else if (count[2] > 1)
      count[2] = count[2] - 2;
    else if (count[2] > 0 && count[5] > 0) {
      count[2]--;
      count[5]--;
    } else if (count[5] > 1)
      count[5] = count[5] - 2;
    else if (count[2] > 0 && count[8] > 0) {
      count[2]--;
      count[8]--;
    } else if (count[5] > 0 && count[8] > 0) {
      count[5]--;
      count[8]--;
    } else
      count[8] = count[8] - 2;
  }
  if (max % 3 == 2) {
    if (count[2] > 0)
      count[2]--;
    else if (count[5] > 0)
      count[5]--;
    else if (count[8] > 0)
      count[8]--;
    else if (count[1] > 1)
      count[1] = count[1] - 2;
    else if (count[1] > 0 && count[4] > 0) {
      count[1]--;
      count[4]--;
    } else if (count[4] > 1)
      count[4] = count[4] - 2;
    else if (count[1] > 0 && count[7] > 0) {
      count[7]--;
      count[1]--;
    } else if (count[4] > 0 && count[7] > 0) {
      count[4]--;
      count[7]--;
    } else
      count[7] = count[7] - 2;
  }
  if (count[9] == 0 && count[8] == 0 && count[7] == 0 && count[6] == 0 &&
      count[5] == 0 && count[4] == 0 && count[3] == 0 && count[2] == 0 &&
      count[1] == 0) {
    cout << 0;
    return 0;
  }
  for (int i = 9; i >= 0; i--)
    for (int j = 0; j < count[i]; j++) cout << i;
}
