#include <bits/stdc++.h>
using namespace std;
static const double PI = 2 * acos(0);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  int modder = 0;
  vector<int> nums(10, 0);
  for (int i = 0; i < (int)(N); i++) {
    int num;
    cin >> num;
    nums[num]++;
    modder = (modder + num) % 3;
  }
  if (nums[0] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  if (modder > 0) {
    for (int i = 0; i < 10; i++) {
      if (i % 3 == modder && nums[i] > 0) {
        modder = 0;
        nums[i]--;
        break;
      }
    }
  }
  if (modder == 2) {
    for (int i = 0; i < 10; i++) {
      if (modder % 3 != 0 && i % 3 == 1 && nums[i] > 0) {
        nums[i]--;
        modder--;
        i -= 1;
      }
    }
  } else if (modder == 1) {
    for (int i = 0; i < 10; i++) {
      if (modder % 3 != 0 && i % 3 == 2 && nums[i] > 0) {
        nums[i]--;
        modder = (modder - 2) % 3;
        i -= 1;
      }
    }
  }
  if (modder > 0) {
    cout << -1 << endl;
  } else {
    for (int i = 9; i >= 0; i--) {
      if (i == 0) {
        cout << 0 << endl;
        return 0;
      }
      if (nums[i] > 0) break;
    }
    for (int i = 9; i >= 0; i--) {
      for (int j = 0; j < (int)(nums[i]); j++) {
        cout << i;
      }
    }
    cout << endl;
  }
  return 0;
}
