#include <bits/stdc++.h>
using namespace std;
long long int cnt[3];
void solve() {
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i] % 3]++;
  }
  sort(a, a + n);
  if (a[0] != 0) {
    cout << -1 << endl;
    return;
  }
  if (a[n - 1] == 0) {
    cout << 0 << endl;
    return;
  }
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) sum += a[i];
  if (sum % 3 == 0) {
    for (long long int i = n - 1; i >= 0; i--) cout << a[i];
    cout << endl;
    return;
  }
  long long int k = sum % 3;
  long long int no = -1;
  for (long long int i = 0; i < n; i++) {
    if (a[i] % 3 == k) {
      no = i;
      break;
    }
  }
  if (no == -1 && cnt[3 - k] < 2) {
    cout << -1 << endl;
    return;
  }
  if (no == -1 && cnt[3 - k] >= 2) {
    long long int cc = -1, dd = -1;
    for (long long int i = 0; i < n; i++) {
      if (a[i] % 3 == 3 - k) {
        if (cc == -1)
          cc = i;
        else if (dd == -1)
          dd = i;
      }
    }
    if (cc == n - 2 && dd == n - 1 && a[n - 3] == 0) {
      cout << 0 << endl;
      return;
    }
    for (long long int i = n - 1; i >= 0; i--) {
      if (i == cc || i == dd) continue;
      cout << a[i];
    }
    return;
  }
  if (no == n - 1) {
    if (a[no - 1] == 0) {
      cout << 0 << endl;
      return;
    }
  }
  for (long long int i = n - 1; i >= 0; i--)
    if (i != no) cout << a[i];
  cout << endl;
}
int main() {
  int T = 1;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  while (T--) solve();
  return 0;
}
