#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, j, k, sum = 0;
  cin >> n;
  map<long long int, long long int> mp;
  for (i = 0; i < n; i++) {
    cin >> k;
    sum += k;
    mp[k] += 1;
  }
  long long int flag = 0;
  if (mp[0] == 0) {
    cout << "-1" << endl;
  } else if (sum == 0) {
    cout << "0" << endl;
  } else {
    if (sum % 3 == 1) {
      flag = 0;
      for (i = 1; i <= 9; i += 3) {
        if (mp[i] > 0) {
          mp[i] -= 1;
          flag = 1;
          break;
        }
      }
      if (flag == 0) {
        k = 2;
        for (i = 2; i <= 9; i += 3) {
          if (mp[i] >= k) {
            mp[i] -= k;
            break;
          } else if (mp[i] == 1) {
            mp[i] -= 1;
            k -= 1;
          }
        }
      }
    } else if (sum % 3 == 2) {
      flag = 0;
      for (i = 2; i <= 9; i += 3) {
        if (mp[i] > 0) {
          mp[i] -= 1;
          flag = 1;
          break;
        }
      }
      if (flag == 0) {
        k = 2;
        for (i = 1; i <= 9; i += 3) {
          if (mp[i] >= k) {
            mp[i] -= k;
            break;
          } else if (mp[i] == 1) {
            mp[i] -= 1;
            k -= 1;
          }
        }
      }
    }
    long long int last, first = INT_MAX;
    string ans;
    for (i = 9; i >= 0; i--) {
      while (mp[i] != 0) {
        ans += char(i + 48);
        mp[i] -= 1;
        last = i;
        if (first == INT_MAX) first = i;
      }
    }
    if (first == last && first == 0)
      cout << "0" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
