#include <bits/stdc++.h>
using namespace std;
const int MAX = (int)(100);
const int OO = (int)(1e9 + 2);
using namespace std;
int main() {
  int n;
  long long sum = 0ll;
  int flag1 = 0, flag2 = 0;
  cin >> n;
  vector<int> nbr, pos1, pos2;
  for (int i = 0; i < (int)(n); ++i) {
    int x;
    cin >> x;
    if (x != 0) flag2++;
    if (x == 0) flag1 = 1;
    nbr.push_back(x);
    sum += x;
  }
  if (!flag1) {
    cout << -1;
    return 0;
  } else if (!flag2) {
    cout << 0;
    return 0;
  } else if ((sum % 3) == 0) {
    sort(nbr.begin(), nbr.end());
    reverse(nbr.begin(), nbr.end());
    for (int i = 0; i < ((int)((nbr).size())); ++i) cout << nbr[i];
    return 0;
  } else {
    sort(nbr.begin(), nbr.end());
    for (int i = 0; i < ((int)((nbr).size())); ++i) {
      if (nbr[i] % 3 == 1) {
        pos1.push_back(i);
      }
      if (nbr[i] % 3 == 2) {
        pos2.push_back(i);
      }
    }
    if ((sum % 3) == 1) {
      if (!(pos1.empty())) {
        if (flag2 == 1) {
          cout << 0;
          return 0;
        }
        reverse(nbr.begin(), nbr.end());
        for (int i = 0; i < ((int)((nbr).size())); ++i) {
          if (i != n - 1 - pos1[0]) cout << nbr[i];
        }
        return 0;
      } else {
        if (flag2 == 2) {
          cout << 0;
          return 0;
        }
        reverse(nbr.begin(), nbr.end());
        for (int i = 0; i < ((int)((nbr).size())); ++i) {
          if ((i != n - 1 - pos2[0]) && ((i != n - 1 - pos2[1])))
            cout << nbr[i];
        }
        return 0;
      }
    }
    if ((sum % 3) == 2) {
      if (!(pos2.empty())) {
        if (flag2 == 1) {
          cout << 0;
          return 0;
        }
        reverse(nbr.begin(), nbr.end());
        for (int i = 0; i < ((int)((nbr).size())); ++i) {
          if (i != n - 1 - pos2[0]) cout << nbr[i];
        }
        return 0;
      } else {
        if (flag2 == 2) {
          cout << 0;
          return 0;
        }
        reverse(nbr.begin(), nbr.end());
        for (int i = 0; i < ((int)((nbr).size())); ++i) {
          if ((i != n - 1 - pos1[0]) && ((i != n - 1 - pos1[1])))
            cout << nbr[i];
        }
        return 0;
      }
    }
  }
  return 0;
}
