#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, n, c, b, d, e, f, h, su;
  long long count[3] = {0};
  cin >> n;
  long long abc[100005];
  long long sum = 0;
  long long flag = 0;
  for (long long i = 0; i < n; i++) {
    cin >> abc[i];
    if (abc[i] == 0) flag = 1;
    sum += abc[i];
    if (abc[i] % 3 == 1) count[1]++;
    if (abc[i] % 3 == 2) count[2]++;
  }
  bool def[100005] = {0};
  if (flag) {
    sort(abc, abc + n);
    if (sum % 3 == 0) {
      if (!sum)
        cout << 0;
      else {
        reverse(abc, abc + n);
        for (long long i = 0; i < n; i++) cout << abc[i];
      }
    } else if (sum % 3 == 1) {
      long long i;
      if (count[1] == 0) {
        e = 2;
        su = sum;
        for (i = 0; i < n; i++) {
          if (abc[i] % 3 == 2) def[i] = 1, e--, su -= abc[i];
          if (e == 0) break;
        }
        if (i == n or !su)
          cout << 0;
        else {
          for (long long i = n - 1; i >= 0; i--) {
            if (def[i])
              continue;
            else
              cout << abc[i];
          }
        }
      } else {
        e = 1;
        su = sum;
        for (i = 0; i < n; i++) {
          if (abc[i] % 3 == 1) def[i] = 1, e--, su -= abc[i];
          if (e == 0) break;
        }
        if (i == n or !su)
          cout << 0;
        else {
          for (long long i = n - 1; i >= 0; i--) {
            if (def[i])
              continue;
            else
              cout << abc[i];
          }
        }
      }
    } else {
      long long i;
      if (count[2] == 0) {
        e = 2;
        su = sum;
        for (i = 0; i < n; i++) {
          if (abc[i] % 3 == 1) def[i] = 1, e--, su -= abc[i];
          if (e == 0) break;
        }
        if (i == n or !su)
          cout << 0;
        else {
          for (long long i = n - 1; i >= 0; i--) {
            if (def[i])
              continue;
            else
              cout << abc[i];
          }
        }
      } else {
        e = 1;
        su = sum;
        for (i = 0; i < n; i++) {
          if (abc[i] % 3 == 2) def[i] = 1, e--, su -= abc[i];
          if (e == 0) break;
        }
        if (i == n or !su)
          cout << 0;
        else {
          for (long long i = n - 1; i >= 0; i--) {
            if (def[i])
              continue;
            else
              cout << abc[i];
          }
        }
      }
    }
  } else
    cout << -1;
  return 0;
}
