#include <bits/stdc++.h>
using namespace std;
const int M = 100000 + 10;
int a[M];
int ihash[20];
int thash[20];
int mhash[20];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    ihash[a[i]]++;
    mhash[a[i] % 3]++;
  }
  bool ok = false;
  bool ok0 = (ihash[0] > 0);
  bool ok1 = (ihash[3] > 0 || ihash[6] > 0 || ihash[9] > 0);
  bool ok2 = ((ihash[1] > 0 && ihash[8] > 0) ||
              (ihash[2] > 0 && ihash[7] > 0) || (ihash[4] > 0 && ihash[5] > 0));
  if (ok0 == true) {
    ok = true;
  }
  if (ok == false) {
    cout << "-1" << endl;
  } else {
    int flag = 0;
    mhash[1] = mhash[1] % 3;
    mhash[2] = mhash[2] % 3;
    if (mhash[1] + 1 == mhash[2]) {
      for (int d = 2; d <= 9; d = d + 3) {
        if (ihash[d] > 0) {
          ihash[d]--;
          break;
        }
      }
    }
    if (mhash[2] + 1 == mhash[1]) {
      for (int d = 1; d <= 9; d = d + 3) {
        if (ihash[d] > 0) {
          ihash[d]--;
          break;
        }
      }
    }
    if (mhash[1] + 2 == mhash[2]) {
      int flag = 0;
      for (int d = 1; d <= 9; d = d + 3) {
        if (ihash[d] > 0) {
          ihash[d]--;
          flag = 1;
          break;
        }
      }
      if (flag == 0) {
        int num = 0;
        for (int d = 2; d <= 9 && num < 2; d = d + 3) {
          while (ihash[d] > 0) {
            ihash[d]--;
            num++;
            if (num == 2) {
              break;
            }
          }
        }
      }
    }
    if (mhash[2] + 2 == mhash[1]) {
      int flag = 0;
      for (int d = 2; d <= 9; d = d + 3) {
        if (ihash[d] > 0) {
          ihash[d]--;
          flag = 1;
          break;
        }
      }
      if (flag == 0) {
        int num = 0;
        for (int d = 1; d <= 9 && num < 2; d = d + 3) {
          while (ihash[d] > 0) {
            ihash[d]--;
            num++;
            if (num == 2) {
              break;
            }
          }
        }
      }
    }
    for (int d = 9; d >= 1; d--) {
      for (int i = 0; i < ihash[d]; i++) {
        cout << d;
        flag = 1;
      }
    }
    if (flag == 1) {
      for (int i = 0; i < ihash[0]; i++) {
        cout << "0";
      }
    } else {
      cout << "0";
    }
    cout << endl;
  }
  return 0;
}
