#include <bits/stdc++.h>
using namespace std;
int n;
int a[100100];
int dig[11];
int ans[11];
int main() {
  int sum = 0;
  bool pos = false;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    dig[a[i]]++;
    sum += a[i];
  }
  if (dig[0] == 0) {
    cout << -1;
    return 0;
  }
  if (sum % 3 == 0) pos = true;
  if (sum % 3 == 1) {
    if (dig[1] > 0) {
      dig[1] -= 1;
      pos = true;
    } else if (dig[4] > 0) {
      pos = true;
      dig[4] -= 1;
    } else if (dig[7] > 0) {
      dig[7] -= 1;
      pos = true;
    } else {
      int a = 10, ai, aj;
      for (int i = 0; i <= 9; i++)
        for (int j = 0; j <= 9; j++)
          if (i != j) {
            if ((i + j) % 3 == 1 && dig[i] > 0 && dig[j] > 0 && max(i, j) < a) {
              a = max(i, j);
              ai = i;
              aj = j;
              pos = true;
            }
          } else {
            if ((i + j) % 3 == 1 && dig[i] > 1 && max(i, j) < a) {
              a = max(i, j);
              ai = i;
              aj = j;
              pos = true;
            }
          }
      dig[ai] -= 1;
      dig[aj] -= 1;
    }
  } else if (sum % 3 == 2) {
    if (dig[2] > 0) {
      dig[2] -= 1;
      pos = true;
    } else if (dig[5] > 0) {
      dig[5] -= 1;
      pos = true;
    } else if (dig[8] > 0) {
      dig[8] -= 1;
      pos = true;
    } else {
      int a = 10, ai, aj;
      for (int i = 0; i <= 9; i++)
        for (int j = 0; j <= 9; j++)
          if (i != j) {
            if ((i + j) % 3 == 2 && dig[i] > 0 && dig[j] > 0 && max(i, j) < a) {
              a = max(i, j);
              ai = i;
              aj = j;
              pos = true;
            }
          } else {
            if ((i + j) % 3 == 2 && dig[i] > 1 && max(i, j) < a) {
              a = max(i, j);
              ai = i;
              aj = j;
              pos = true;
            }
          }
      dig[ai] -= 1;
      dig[aj] -= 1;
    }
  }
  if (pos) {
    bool shown = false;
    for (int i = 9; i > 0; i--)
      for (int j = 0; j < dig[i]; j++) {
        cout << i;
        shown = true;
      }
    if (shown)
      for (int j = 0; j < dig[0]; j++) cout << 0;
    else
      cout << 0;
  } else
    cout << 0;
}
