#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> cnt(10, 0);
  for (int i = 0; i < n; ++i) {
    int d;
    cin >> d;
    ++cnt[d];
  }
  if (cnt[0] == 0) {
    cout << -1 << '\n';
    return 0;
  }
  int digit_sum = 0;
  for (int i = 0; i < 10; ++i) {
    digit_sum += i * cnt[i];
  }
  for (int i = digit_sum % 3; i < 10; i += 3) {
    while (digit_sum % 3 != 0 && cnt[i] != 0) {
      --cnt[i];
      digit_sum -= i;
    }
  }
  for (int i = (2 * digit_sum) % 3; i < 10; i += 3) {
    while (digit_sum % 3 != 0 && cnt[i] != 0) {
      --cnt[i];
      digit_sum -= i;
    }
  }
  if (digit_sum == 0) {
    cout << 0 << '\n';
    return 0;
  }
  for (int i = 9; i >= 0; --i) {
    for (int j = 0; j < cnt[i]; ++j) {
      cout << i;
    }
  }
  cout << '\n';
  return 0;
}
