#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> arr(n);
  int sum = 0, flag = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    sum += arr[i];
    if (arr[i] == 0) {
      flag = 1;
    }
  }
  if (flag == 0) {
    printf("-1\n");
    return 0;
  }
  sort(arr.begin(), arr.end());
  if (sum % 3 == 0) {
    if (sum == 0) {
      printf("0\n");
      return 0;
    }
    for (int i = n - 1; i >= 0; i--) {
      printf("%d", arr[i]);
    }
  } else {
    flag = 2;
    int rem = sum % 3;
    for (int i = 0; i < n; i++) {
      if (arr[i] % 3 == rem) {
        sum -= arr[i];
        arr.erase(arr.begin() + i);
        flag = 0;
        break;
      }
    }
    if (flag == 2) {
      for (int i = 0; i < n; i++) {
        if (arr[i] % 3 == (3 - rem)) {
          sum -= arr[i];
          arr.erase(arr.begin() + i);
          i--;
          flag--;
        }
        if (flag == 0) {
          break;
        }
      }
    }
    if (sum == 0) {
      printf("0\n");
      return 0;
    }
    if (flag != 0) {
      printf("-1\n");
    } else {
      for (int i = arr.size() - 1; i >= 0; i--) {
        printf("%d", arr[i]);
      }
    }
  }
  return 0;
}
