#include <bits/stdc++.h>
using namespace std;
int n;
int arr[100];
int main() {
  cin >> n;
  int sum = 0;
  int uu = 0;
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    arr[k]++;
    sum = sum + k;
    if (k != 0) uu = 1;
  }
  if (uu == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (arr[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  int f = 0;
  if (sum % 3 == 0)
    f = 1;
  else if (sum % 3 == 2) {
    if (arr[2] != 0) {
      arr[2]--;
      f = 1;
    } else if (arr[5] != 0) {
      arr[5]--;
      f = 1;
    } else if (arr[8] != 0) {
      arr[8]--;
      f = 1;
    } else if (arr[1] >= 2) {
      arr[1] -= 2;
      f = 1;
    } else if (arr[4] != 0 && arr[1] != 0) {
      arr[4]--;
      arr[1]--;
      f = 1;
    } else if (arr[4] >= 2) {
      arr[4] -= 2;
      f = 1;
    } else if (arr[7] != 0 && arr[1] != 0) {
      arr[7]--;
      arr[1]--;
      f = 1;
    } else if (arr[7] != 0 && arr[4] != 0) {
      arr[7]--;
      arr[4]--;
      f = 1;
    } else if (arr[7] >= 2) {
      arr[7] -= 2;
      f = 1;
    }
  } else if (sum % 3 == 1) {
    if (arr[1] != 0) {
      arr[1]--;
      f = 1;
    } else if (arr[4] != 0) {
      arr[4]--;
      f = 1;
    } else if (arr[7] != 0) {
      arr[7]--;
      f = 1;
    } else if (arr[2] >= 2) {
      arr[2] -= 2;
      f = 1;
    } else if (arr[5] != 0 && arr[2] != 0) {
      arr[5]--;
      arr[2]--;
      f = 1;
    } else if (arr[5] >= 2) {
      arr[5] -= 2;
      f = 1;
    } else if (arr[8] != 0 && arr[2] != 0) {
      arr[8]--;
      arr[2]--;
      f = 1;
    } else if (arr[8] != 0 && arr[5] != 0) {
      arr[8]--;
      arr[5]--;
      f = 1;
    } else if (arr[8] >= 2) {
      arr[8] -= 2;
      f = 1;
    }
  }
  if (f == 1) {
    int cc = 0;
    for (int i = 1; i <= 9; i++) {
      if (arr[i] == 0)
        cc = 1;
      else {
        cc = 0;
        break;
      }
    }
    if (cc == 1) {
      cout << 0 << endl;
    } else {
      for (int i = 9; i >= 0; i--) {
        for (int j = 1; j <= arr[i]; j++) cout << i;
      }
      cout << endl;
    }
  } else {
    cout << 0 << endl;
  }
  return 0;
}
