#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s = 0, sum = 0;
  cin >> n;
  vector<int> d(10, 0);
  vector<int> m(3, 0);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    d[a]++;
    m[a % 3]++;
    s += a;
    sum += a;
    s %= 3;
  }
  if (d[0] == 0) {
    cout << -1;
    return 0;
  }
  if (s != 0) {
    if (m[s] != 0) {
      for (int i = s; i < 10; i += 3) {
        if (d[i] > 0) {
          if (d[i] > 0) {
            d[i]--;
          }
          break;
        }
      }
    } else {
      while (sum % 3 != 0) {
        int i = 3 - s;
        for (; i < 10; i += 3) {
          if (d[i] > 0) {
            d[i]--;
            sum -= i;
            break;
          }
        }
      }
      if (sum == 0) {
        cout << 0;
        return 0;
      }
    }
  }
  bool p = false;
  for (int i = 9; i >= 0; i--) {
    if (i == 0 && !p) {
      cout << 0;
      return 0;
    }
    while (d[i] > 0) {
      cout << i;
      d[i]--;
      p = true;
    }
  }
  return 0;
}
