#include <bits/stdc++.h>
using namespace std;
int n, x, tot, f;
int a[20] = {};
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    tot += x;
    a[x]++;
  }
  if (a[0] == 0) {
    cout << "-1" << endl;
  } else {
    if (tot % 3 != 0) {
      for (int i = 1; i <= 8; i++) {
        if ((a[i] != 0) && ((tot - i) % 3 == 0)) {
          a[i]--;
          tot -= i;
          break;
        }
      }
    }
    if (tot % 3 != 0) {
      for (int i = 1; i <= 8; i++) {
        if ((a[i] != 0) && (i % 3 != 0)) {
          a[i]--;
          tot -= i;
          if (tot % 3 != 0)
            i--;
          else
            break;
        }
      }
    }
    if (tot % 3 != 0) {
      cout << "-1" << endl;
      return 0;
    }
    for (int i = 9; i >= 1; i--) {
      if (a[i] != 0) f = 1;
      for (int j = 1; j <= a[i]; j++) {
        printf("%d", i);
      }
    }
    if (f != 0) {
      for (int j = 1; j <= a[0]; j++) {
        printf("%d", 0);
      }
    } else {
      cout << "0";
    }
    cout << endl;
  }
}
