#include <bits/stdc++.h>
using namespace std;
int arr[100005];
int main() {
  int n;
  cin >> n;
  int z = 0, sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    if (arr[i] == 0) z++;
    sum += arr[i];
  }
  if (z == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (z == n) {
    cout << 0 << endl;
    return 0;
  }
  sort(arr + 1, arr + 1 + n);
  if (sum % 3 == 0) {
    for (int i = n; i >= 1; i--) printf("%d", arr[i]);
    puts("");
  } else {
    int md = sum % 3;
    int zr = 0;
    if (md == 1) {
      int ch = 0;
      for (int i = 1; i <= n; i++) {
        if (arr[i] % 3 == 1) {
          ch = 1;
          arr[i] = -1;
          break;
        }
      }
      if (ch == 0) {
        int m = 0;
        for (int i = 1; i <= n; i++) {
          if (arr[i] % 3 == 2) {
            m++;
            arr[i] = -1;
            if (m == 2) {
              ch = 1;
              break;
            }
          }
        }
      }
      sort(arr + 1, arr + 1 + n);
      if (ch == 1) {
        for (int i = n; i >= 1; i--) {
          if (i == n && arr[i] == 0) {
            cout << 0 << endl;
            return 0;
          }
          if (arr[i] != -1) {
            printf("%d", arr[i]);
          }
        }
        puts("");
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
    if (md == 2) {
      int ch = 0;
      for (int i = 1; i <= n; i++) {
        if (arr[i] % 3 == 2) {
          ch = 1;
          arr[i] = -1;
          break;
        }
      }
      if (ch == 0) {
        int m = 0;
        for (int i = 1; i <= n; i++) {
          if (arr[i] % 3 == 1) {
            m++;
            arr[i] = -1;
            if (m == 2) {
              ch = 1;
              break;
            }
          }
        }
      }
      sort(arr + 1, arr + 1 + n);
      if (ch == 1) {
        for (int i = n; i >= 1; i--) {
          if (i == n && arr[i] == 0) {
            cout << 0 << endl;
            return 0;
          }
          if (arr[i] != -1) printf("%d", arr[i]);
        }
        puts("");
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  return 0;
}
