#include <bits/stdc++.h>
using namespace std;
void print(int a[]) {
  for (int i = 9; i >= 0; i--) {
    while (a[i]--) {
      cout << i;
    }
  }
  cout << endl;
}
bool dfs(int i, int a[]) {
  if (i == 0) {
    int res = 0;
    for (int j = 0; j <= 9; j++) res += a[j] * j;
    if (res % 3 == 0) {
      if (res == 0)
        cout << "0" << endl;
      else
        print(a);
      return true;
    }
    return false;
  }
  for (int k = 1; k <= 9; k++) {
    if (a[k] > 0) {
      a[k]--;
      if (dfs(i - 1, a)) {
        return true;
      }
      a[k]++;
    }
  }
  return false;
}
int main() {
  int n, tmp, a[10] = {0}, sum = 0;
  cin >> n;
  int i = n;
  while (i--) {
    cin >> tmp;
    a[tmp]++;
    sum += tmp;
  }
  if (sum % 3 == 0 && a[0] > 0) {
    if (sum == 0)
      cout << "0" << endl;
    else
      print(a);
  } else if (a[0] <= 0)
    cout << "-1" << endl;
  else {
    for (i = 1; i < n; i++) {
      if (dfs(i, a)) break;
    }
    if (i >= n) cout << "-1" << endl;
  }
  return 0;
}
