#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[100010], arr1[101000];
  for (int i = 0; i < (n); i++) cin >> arr1[i];
  sort(arr1, arr1 + n);
  int tal = 0;
  for (int i = 0; i < (n); i++) arr[i] = arr1[n - 1 - i];
  for (int i = 0; i < (n); i++)
    if (arr[i] != 0) tal++;
  if (n > 1 && arr[0] == 0)
    cout << 0 << endl;
  else if (n == 1) {
    if (arr[0] == 0)
      cout << 0 << endl;
    else
      cout << -1 << endl;
  } else {
    if (arr[n - 1] == 0) {
      int sum = 0;
      for (int i = 0; i < (n); i++) sum += arr[i];
      if (sum % 3 != 0) {
        int flag = 0;
        for (int i = n - 1; i >= 0; i--) {
          if ((arr[i] % 3) == (sum % 3) && tal > 1) {
            for (int j = 0; j < (n); j++)
              if (j != i) cout << arr[j];
            cout << endl;
            flag = 1;
            break;
          }
        }
        int cnt = 0;
        for (int i = n - 1; i >= 0; i--) {
          if (arr[i] % 3 == 3 - sum % 3) cnt++;
        }
        if (cnt > 1 && flag == 0 && tal > 2) {
          int temp[100010], q = 0;
          cnt = 2;
          for (int i = n - 1; i >= 0; i--) {
            if (arr[i] % 3 == 3 - sum % 3) {
              if (cnt > 0)
                cnt--;
              else {
                temp[q] = arr[i];
                q++;
              }
            } else {
              temp[q] = arr[i];
              q++;
            }
          }
          for (int i = q - 1; i >= 0; i--) cout << temp[i];
          cout << endl;
          flag = 1;
        }
        if (flag == 0) cout << 0 << endl;
      } else {
        for (int j = 0; j < (n); j++) cout << arr[j];
        cout << endl;
      }
    } else
      cout << -1 << endl;
  }
  return 0;
}
