#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int counter[10] = {0};
  int total = 0;
  while (n--) {
    int temp;
    cin >> temp;
    ++counter[temp];
    total += temp;
  }
  if (counter[0]) {
    if (total % 3 == 1) {
      for (int i = 1; i <= 9; i += 3)
        if (counter[i]) {
          --counter[i];
          total -= i;
          break;
        }
      for (int i = 2; i <= 9 && (total % 3); i += 3)
        if (counter[i]) {
          --counter[i];
          total -= i;
          i -= 3;
        }
    } else if (total % 3 == 2) {
      for (int i = 2; i <= 9; i += 3)
        if (counter[i]) {
          --counter[i];
          total -= i;
          break;
        }
      for (int i = 1; i <= 9 && (total % 3); i += 3)
        if (counter[i]) {
          --counter[i];
          total -= i;
          i -= 3;
        }
    }
    if (total == 0 || (total % 3))
      cout << "0\n";
    else {
      for (int i = 9; i >= 0; --i)
        while (counter[i]) {
          --counter[i];
          cout << i;
        }
      cout << "\n";
    }
  } else {
    cout << "-1\n";
  }
  return 0;
}
