#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
  };
  int n, sum = 0, zero = 0;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    if (!v[i]) zero = 1;
    sum += v[i];
  }
  if (!zero) {
    cout << -1;
    return 0;
  }
  int need = sum % 3, alt = 0, done = 0, altdone = 0;
  if (need == 1)
    alt = 2;
  else if (need == 2)
    alt = 1;
  sort(v.begin(), v.end(), greater<int>());
  if (need) {
    for (int i = n - 1; i >= 0; i--) {
      if (v[i] % 3 == need) {
        v[i] = -1;
        done = 1;
        break;
      }
    }
    if (!done) {
      for (int i = n - 1; i >= 0; i--) {
        if (v[i] % 3 == alt) altdone++, v[i] = -1;
        if (altdone == 2) {
          break;
        }
      }
    }
  } else {
    done = 1;
  }
  int printing_started = 0;
  if (done || altdone == 2) {
    for (int i = 0; i < n; i++)
      if (v[i] != -1) {
        cout << v[i];
        if (!v[i] && !printing_started) {
          break;
        }
        printing_started = 1;
      }
  } else {
    cout << -1;
  }
  return 0;
}
