#include <bits/stdc++.h>
using namespace std;
class compare {
 public:
  bool operator()(pair<long long, long long> a, pair<long long, long long> b) {
    if (a.first > b.first) return true;
    return false;
  }
};
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.second > b.second)
    return true;
  else if (a.second == b.second) {
    return a.first < b.first;
  } else {
    return false;
  }
}
long long power(long long a, long long b) {
  long long res = 1;
  a = a % 1000000007;
  while (b) {
    if (b & 1) {
      res = (res * a) % 1000000007;
    }
    b /= 2;
    a = (a * a) % 1000000007;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long tc = 1;
  while (tc--) {
    long long n;
    cin >> n;
    long long a[n], h[10] = {0}, s = 0;
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      h[a[i]]++;
      s += a[i];
    }
    sort(a, a + n);
    if (h[0] == 0) return cout << -1, 0;
    if (h[0] == n) return cout << 0, 0;
    s %= 3;
    if (s == 0) {
      for (long long i = n - 1; i >= 0; i--) cout << a[i];
      return 0;
    }
    long long f = 0;
    for (long long i = 0; i < 10; i++) {
      if (h[i] && i % 3 == s) {
        f = 1;
        h[i]--;
        break;
      }
    }
    if (!f) {
      for (long long i = 0; i < 10; i++) {
        for (long long j = 0; j < 10; j++) {
          if (h[i] && h[j] && i != j && (i + j) % 3 == s) {
            f = 1;
            h[i]--;
            h[j]--;
            i = 10;
            j = 10;
          }
          if (i == j && h[i] > 1 && (i + j) % 3 == s) {
            f = 1;
            h[i] -= 2;
            i = 10;
            j = 10;
          }
        }
      }
    }
    long long f1 = 0;
    if (f) {
      for (long long i = 9; i > 0; i--) {
        while (h[i]) {
          f1 = 1;
          cout << i;
          h[i]--;
        }
      }
      if (f1) {
        for (long long i = 0; i < h[0]; i++) cout << 0;
      } else
        cout << 0;
    } else
      cout << -1;
  }
}
