#include <bits/stdc++.h>
using namespace std;
vector<int> mod_1, mod_0, mod_2, mod_, ans;
int main() {
  int n;
  cin >> n;
  bool c = false;
  int x;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    sum += x;
    mod_.push_back(x);
    if (x % 3 == 0)
      mod_0.push_back(x);
    else if (x % 3 == 1)
      mod_1.push_back(x);
    else
      mod_2.push_back(x);
    if (x == 0) c = true;
  }
  if (!c) {
    cout << "-1" << endl;
    return 0;
  }
  sort(mod_1.rbegin(), mod_1.rend());
  sort(mod_2.rbegin(), mod_2.rend());
  sort(mod_.rbegin(), mod_.rend());
  if (sum % 3 == 0) {
    if (mod_[0] == 0)
      return cout << 0, 0;
    else {
      for (int i = 0; i < mod_.size(); i++) {
        printf("%d", mod_[i]);
      }
    }
    return 0;
  } else if (sum % 3 == 1) {
    if (mod_1.size())
      mod_1.pop_back();
    else if (mod_2.size() > 1) {
      mod_2.pop_back();
      mod_2.pop_back();
    } else
      return cout << -1, 0;
  } else {
    if (mod_2.size())
      mod_2.pop_back();
    else if (mod_1.size() > 1) {
      mod_1.pop_back();
      mod_1.pop_back();
    } else
      return cout << -1, 0;
  }
  for (int i = 0; i < mod_0.size(); i++) ans.push_back(mod_0[i]);
  for (int i = 0; i < mod_2.size(); i++) ans.push_back(mod_2[i]);
  for (int i = 0; i < mod_1.size(); i++) ans.push_back(mod_1[i]);
  sort(ans.rbegin(), ans.rend());
  if (!ans[0])
    cout << 0;
  else
    for (int i = 0; i < ans.size(); i++) cout << ans[i];
  return 0;
}
