#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n);
  long long s = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  sort((a).begin(), (a).end(), greater<long long>());
  if (a.back() != 0)
    cout << -1;
  else {
    if (s % 3 == 0)
      if (s != 0)
        for (long long i = 0; i < n; i++) cout << a[i];
      else
        cout << 0;
    else if (s % 3 == 1) {
      for (long long i = n - 1; i > -1; i--) {
        if (a[i] % 3 == 1) {
          s -= a[i];
          a.erase(a.begin() + i);
          if (s != 0)
            for (long long i = 0; i < a.size(); i++) cout << a[i];
          else
            cout << 0;
          return 0;
        }
      }
      long long c = 2;
      for (long long i = n - 1; i > -1; i--) {
        if (a[i] % 3 == 2) {
          s -= a[i];
          a.erase(a.begin() + i);
          c--;
          if (c == 0) {
            if (s != 0)
              for (long long i = 0; i < a.size(); i++) cout << a[i];
            else
              cout << 0;
            return 0;
          }
        }
      }
      cout << 0;
    } else if (s % 3 == 2) {
      for (long long i = n - 1; i > -1; i--) {
        if (a[i] % 3 == 2) {
          s -= a[i];
          a.erase(a.begin() + i);
          if (s != 0)
            for (long long i = 0; i < a.size(); i++) cout << a[i];
          else
            cout << 0;
          return 0;
        }
      }
      long long c = 2;
      for (long long i = n - 1; i > -1; i--) {
        if (a[i] % 3 == 1) {
          s -= a[i];
          a.erase(a.begin() + i);
          c--;
          if (c == 0) {
            if (s != 0)
              for (long long i = 0; i < a.size(); i++) cout << a[i];
            else
              cout << 0;
            return 0;
          }
        }
      }
      cout << 0;
    }
  }
}
