#include <bits/stdc++.h>
using namespace std;
int A[100000];
vector<int> Az;
pair<int, pair<int, int> > pre[100001][3];
int dp[100001][3];
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int zeropos = -1;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (zeropos == -1 && !A[i]) {
      zeropos = i;
    }
  }
  if (zeropos == -1) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    if (i == zeropos) continue;
    Az.push_back(A[i]);
  }
  sort(Az.begin(), Az.end(), greater<int>());
  int sum = 0;
  for (int i = 0; i < Az.size(); i++) {
    sum = (sum + Az[i]) % 3;
  }
  if (!sum) {
    if (!Az.size() || Az[0] == 0) {
      cout << 0;
      return 0;
    }
    for (int i = 0; i < Az.size(); i++) {
      cout << Az[i];
    }
    cout << 0;
  } else {
    int i;
    for (i = Az.size() - 1; i >= 0; i--) {
      if (Az[i] % 3 == sum) {
        break;
      }
    }
    if (i != -1) {
      vector<int> res;
      for (int j = 0; j < Az.size(); j++) {
        if (j == i) {
          continue;
        }
        res.push_back(Az[j]);
      }
      if (!res.size() || res[0] == 0) {
        cout << 0;
        return 0;
      }
      for (int j = 0; j < res.size(); j++) {
        cout << res[j];
      }
      cout << 0;
    } else {
      if (sum == 1) {
        int first = -1, second = -1;
        for (i = Az.size() - 1; i >= 0; i--) {
          if (Az[i] % 3 == 2) {
            if (first == -1) {
              first = i;
            } else {
              second = i;
              break;
            }
          }
        }
        if (first != -1 && second != -1) {
          vector<int> res;
          for (int j = 0; j < Az.size(); j++) {
            if (j == first || j == second) {
              continue;
            }
            res.push_back(Az[j]);
          }
          if (!res.size() || res[0] == 0) {
            cout << 0;
            return 0;
          }
          for (int j = 0; j < res.size(); j++) {
            cout << res[j];
          }
          cout << 0;
        }
      } else {
        int first = -1, second = -1;
        for (i = Az.size() - 1; i >= 0; i--) {
          if (Az[i] % 3 == 1) {
            if (first == -1) {
              first = i;
            } else {
              second = i;
              break;
            }
          }
        }
        if (first != -1 && second != -1) {
          vector<int> res;
          for (int j = 0; j < Az.size(); j++) {
            if (j == first || j == second) {
              continue;
            }
            res.push_back(Az[j]);
          }
          if (!res.size() || res[0] == 0) {
            cout << 0;
            return 0;
          }
          for (int j = 0; j < res.size(); j++) {
            cout << res[j];
          }
          cout << 0;
        }
      }
    }
  }
  return 0;
}
