#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, j, zero = 0, sum = 0;
  cin >> n;
  vector<long long int> second;
  vector<long long int> ans;
  map<long long int, long long int> m;
  for (long long int i = 0; i < n; i++) {
    cin >> j;
    if (j == 0) zero++;
    sum = sum + j;
    second.push_back(j);
    m[j]++;
  }
  if (zero == 0) {
    ans.push_back(-1);
  } else if (sum == 0) {
    ans.push_back(0);
  } else if (m[0] == n) {
    ans.push_back(0);
  } else {
    if (sum % 3 == 0) {
      for (auto iter = m.rbegin(); iter != m.rend(); ++iter) {
        while (iter->second--) ans.push_back(iter->first);
      }
    } else if (sum % 3 == 1) {
      long long int yoo = 0;
      for (auto it = m.begin(); it != m.end(); it++) {
        if (it->first % 3 == 1) {
          it->second--;
          yoo++;
          break;
        }
      }
      if (yoo) {
        for (auto iter = m.rbegin(); iter != m.rend(); ++iter) {
          while (iter->second--) ans.push_back(iter->first);
        }
      } else {
        long long int yoo = 0;
        for (auto it = m.begin(); it != m.end(); it++) {
          if (it->first % 3 == 2) {
            it->second--;
            yoo++;
            if (it->second != 0 && yoo < 2) {
              it->second--;
              yoo++;
            }
            if (yoo == 2) break;
          }
        }
        if (yoo == 2) {
          if (yoo) {
            for (auto iter = m.rbegin(); iter != m.rend(); ++iter) {
              while (iter->second--) ans.push_back(iter->first);
            }
          }
        } else
          ans.push_back(0);
      }
    } else if (sum % 3 == 2) {
      long long int yoo = 0;
      for (auto it = m.begin(); it != m.end(); it++) {
        if (it->first % 3 == 2) {
          it->second--;
          yoo++;
          break;
        }
      }
      if (yoo) {
        for (auto iter = m.rbegin(); iter != m.rend(); ++iter) {
          while (iter->second--) ans.push_back(iter->first);
        }
      } else {
        long long int yoo = 0;
        for (auto it = m.begin(); it != m.end(); it++) {
          if (it->first % 3 == 1) {
            it->second--;
            yoo++;
            if (it->second != 0 && yoo < 2) {
              it->second--;
              yoo++;
            }
            if (yoo == 2) break;
          }
        }
        if (yoo == 2) {
          for (auto iter = m.rbegin(); iter != m.rend(); ++iter) {
            while (iter->second--) ans.push_back(iter->first);
          }
        } else
          ans.push_back(0);
      }
    }
  }
  long long int zoo = 0;
  for (long long int i = 0; i < ans.size(); i++) {
    if (ans[i] == 0) zoo++;
  }
  if (zoo == ans.size()) {
    cout << 0 << "\n";
  } else {
    for (long long int i = 0; i < ans.size(); i++) {
      cout << ans[i];
    }
    cout << "\n";
  }
}
