#include <bits/stdc++.h>
using namespace std;
int digit[100001];
bool cmp(int a, int b) { return a > b; }
int main() {
  int n;
  scanf("%d", &n);
  bool c = false;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &digit[i]);
    if (digit[i] == 0) c = true;
    sum += digit[i];
  }
  if (c == false) {
    cout << -1 << endl;
  } else {
    sort(digit, digit + n, cmp);
    if (sum % 3 == 0) {
      if (digit[0] == 0)
        cout << 0;
      else {
        for (int i = 0; i < n; i++) printf("%d", digit[i]);
      }
    } else {
      for (int i = n - 1; i >= 0; i--) {
        if (digit[i] % 3 == sum % 3) {
          sum -= digit[i];
          digit[i] = -1;
          break;
        }
      }
      if (sum % 3 != 0) {
        int smp;
        if (sum % 3 == 1)
          smp = 2;
        else
          smp = 1;
        for (int i = n - 1; i >= 0; i--) {
          if ((digit[i] % 3 == smp) && (sum % 3 != 0)) {
            sum -= digit[i];
            digit[i] = -1;
          }
          if (sum % 3 == 0) break;
        }
      }
      int temp = -1;
      for (int i = 0; i < n; i++) {
        if (digit[i] >= 0) {
          if (temp == -1) temp = digit[i];
          if (temp == 0) {
            cout << 0;
            return 0;
          } else {
            printf("%d", digit[i]);
          }
        }
      }
    }
  }
  return 0;
}
