#include <bits/stdc++.h>
using namespace std;
int arr[100007];
bool visited[100007];
int main() {
  int n;
  cin >> n;
  int summ = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    summ += arr[i];
  }
  sort(arr, arr + n);
  if (arr[0] != 0) {
    cout << -1 << "\n";
    return 0;
  }
  if (summ % 3 == 0) {
    if (arr[n - 1] == 0)
      cout << 0 << "\n";
    else {
      for (int i = n - 1; i >= 0; i--) cout << arr[i];
      cout << "\n";
    }
    return 0;
  }
  int rem = summ % 3;
  bool f = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] % 3 == rem) {
      f = 1;
      visited[i] = 1;
      break;
    }
  }
  int cnt = 0;
  for (int i = 0; i < n && !f; i++) {
    if (cnt == 2) {
      f = 1;
      break;
    }
    if (arr[i] % 3 == 3 - rem) {
      cnt++;
      visited[i] = 1;
    }
  }
  string ans = "";
  for (int i = n - 1; i >= 0; i--) {
    if (visited[i]) continue;
    ans += (char)(arr[i] + '0');
  }
  if (ans[0] == '0')
    cout << "0\n";
  else
    cout << ans << "\n";
  return 0;
}
