#include <bits/stdc++.h>
using namespace std;
bool prime[100000 + 1];
void sieve() {
  memset(prime, true, sizeof(prime));
  for (long p = 2; p * p <= 100000; p++) {
    if (prime[p] == true) {
      for (long i = p * p; i <= 100000; i += p) prime[i] = false;
    }
  }
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long power(int v, int a) {
  long prod = 1;
  for (int i = 0; i < a; i++) prod *= v;
  return prod;
}
int countFreq(string &pat, string &txt) {
  int M = pat.length();
  int N = txt.length();
  int res = 0;
  for (int i = 0; i <= N - M; i++) {
    int j;
    for (j = 0; j < M; j++)
      if (txt[i + j] != pat[j]) break;
    if (j == M) {
      res++;
      j = 0;
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int T = 1;
  while (T--) {
    int n, b;
    cin >> n;
    long long sum = 0;
    bool chill = 0;
    int a[10];
    memset(a, 0, sizeof(a));
    for (int i = 0; i < n; i++) {
      cin >> b;
      if (b != 0) chill = 1;
      a[b]++;
      sum += b;
    }
    if (a[0] == 0)
      cout << -1;
    else {
      int t = sum % 3;
      if (t == 1) {
        int one = -1, t1 = -1, t2 = -1;
        for (int i = 1; i < 10; i += 3)
          if (a[i]) {
            one = i;
            break;
          }
        for (int i = 2; i < 10; i += 3) {
          if (a[i]) {
            if (t1 == -1)
              t1 = i;
            else {
              t2 = i;
              break;
            }
          }
        }
        if (t1 != -1 && t2 == -1) {
          if (a[t1] > 1) {
            if (one == -1 || 2 * t1 < one)
              a[t1] -= 2;
            else
              a[one]--;
          } else
            a[one]--;
        } else if (t1 == -1)
          a[one]--;
        else {
          if (one == -1) {
            if (a[t1] > 1) {
              if (t1 + t2 < 2 * t1) {
                a[t1]--;
                a[t2]--;
              } else
                a[t1] -= 2;
            } else {
              a[t1]--;
              a[t2]--;
            }
          } else {
            if (a[t1] > 1) {
              if (t + t2 < 2 * t1) {
                if (t1 + t2 < one) {
                  a[t1]--;
                  a[t2]--;
                } else
                  a[one]--;
              } else {
                if (2 * t1 < one) {
                  a[t1]--;
                  a[t2]--;
                } else
                  a[one]--;
              }
            } else {
              if (t1 + t2 < one) {
                a[t1]--;
                a[t2]--;
              } else
                a[one]--;
            }
          }
        }
      }
      if (t == 2) {
        int one = -1, t1 = -1, t2 = -1;
        for (int i = 2; i < 10; i += 3)
          if (a[i]) {
            one = i;
            break;
          }
        for (int i = 1; i < 10; i += 3) {
          if (a[i]) {
            if (t1 == -1)
              t1 = i;
            else {
              t2 = i;
              break;
            }
          }
        }
        if (t1 != -1 && t2 == -1) {
          if (a[t1] > 1) {
            if (one == -1 || 2 * t1 < one)
              a[t1] -= 2;
            else
              a[one]--;
          } else
            a[one]--;
        } else if (t1 == -1)
          a[one]--;
        else {
          if (one == -1) {
            if (a[t1] > 1) {
              if (t1 + t2 < 2 * t1) {
                a[t1]--;
                a[t2]--;
              } else
                a[t1] -= 2;
            } else {
              a[t1]--;
              a[t2]--;
            }
          } else {
            if (a[t1] > 1) {
              if (t + t2 < 2 * t1) {
                if (t1 + t2 < one) {
                  a[t1]--;
                  a[t2]--;
                } else
                  a[one]--;
              } else {
                if (2 * t1 < one) {
                  a[t1]--;
                  a[t2]--;
                } else
                  a[one]--;
              }
            } else {
              if (t1 + t2 < one) {
                a[t1]--;
                a[t2]--;
              } else
                a[one]--;
            }
          }
        }
      }
      bool extra = 0;
      for (int i = 1; i < 10; i++)
        if (a[i]) {
          extra = 1;
          break;
        }
      if (!extra)
        cout << 0;
      else {
        for (int i = 9; i >= 0; i--) {
          for (int j = 0; j < a[i]; j++) cout << i;
        }
      }
      cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    }
  }
  return 0;
}
