#include <bits/stdc++.h>
using namespace std;
int vet[11];
vector<int> ans, maxi, rando;
vector<int> mo[3];
long long soma = 0;
int main() {
  int n, val;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &val);
    ans.push_back(val);
    soma += val;
    mo[val % 3].push_back(val);
  }
  for (int i = 0; i < 3; i++) sort(mo[i].begin(), mo[i].end());
  long long v1 = soma % 3;
  sort(ans.begin(), ans.end(), greater<int>());
  if (ans.back() != 0)
    cout << "-1";
  else {
    if (v1 == 1) {
      if (mo[1].size() != 0) {
        auto it = find(ans.begin(), ans.end(), mo[1][0]);
        ans.erase(it);
      } else {
        auto it = find(ans.begin(), ans.end(), mo[2][0]);
        ans.erase(it);
        auto it2 = find(ans.begin(), ans.end(), mo[2][1]);
        ans.erase(it2);
      }
    } else if (v1 == 2) {
      if (mo[2].size() != 0) {
        auto it = find(ans.begin(), ans.end(), mo[2][0]);
        ans.erase(it);
      } else {
        auto it = find(ans.begin(), ans.end(), mo[1][0]);
        ans.erase(it);
        auto it2 = find(ans.begin(), ans.end(), mo[1][1]);
        ans.erase(it2);
      }
    }
    if (ans[0] == 0)
      cout << 0;
    else
      for (auto it : ans) cout << it;
  }
}
