#include <bits/stdc++.h>
using namespace std;
void printer(vector<int>& mas) {
  bool ip = true;
  for (int i = 9; i >= 0; --i) {
    for (int j = 0; j < mas[i]; ++j) {
      if (ip && i == 0) {
        cout << i;
        exit(0);
      }
      cout << i;
      if (i != 0) ip = false;
    }
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> mas(10, 0);
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    mas[a]++;
    sum += a;
  }
  if (mas[0] == 0) {
    cout << -1;
  } else if (sum == 0) {
    cout << 0;
  } else if (sum % 3 == 0) {
    printer(mas);
  } else {
    for (int i = 1; i <= 9; ++i) {
      if (mas[i] > 0 && (sum - i) % 3 == 0) {
        mas[i]--;
        printer(mas);
        exit(0);
      }
    }
    for (int i = 1; i <= 9; ++i) {
      for (int j = 1; j <= 9; ++j) {
        if (mas[i] > 0 && mas[j] > 0 && (sum - i - j) % 3 == 0) {
          if (i == j && mas[i] == 1) {
            continue;
          }
          mas[i]--;
          mas[j]--;
          printer(mas);
          exit(0);
        }
      }
    }
    cout << -1;
  }
}
