#include <bits/stdc++.h>
using namespace std;
string arr;
int num[10];
int n, sum = 0;
void print(int n1 = -1, int n2 = -1) {
  if (sum == 0) {
    cout << 0;
    return;
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] - 48 == n1) {
      n1 = -1;
      continue;
    } else if (arr[i] - 48 == n2) {
      n2 = -1;
      continue;
    }
    cout << arr[i];
  }
}
void getNumber(int Orgmod, int mod) {
  int a = -1, b = -1;
  for (int i = 1; i < 10; i++) {
    if (num[i] > 0 && i % 3 == Orgmod) {
      sum -= i;
      print(i);
      return;
    }
    if (num[i] > 0 && i % 3 == mod && a == -1) {
      a = i;
      num[i]--;
    }
    if (num[i] > 0 && i % 3 == mod && b == -1) {
      b = i;
      num[i]--;
    }
  }
  if (a != -1 && b != -1)
    sum -= a, sum -= b, print(a, b);
  else
    cout << -1;
}
int main() {
  char ch;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ch;
    arr += ch;
    sum += (ch - 48);
    num[ch - 48]++;
  }
  sort(arr.rbegin(), arr.rend());
  if (arr[n - 1] == '0') {
    if (sum % 3 == 0) {
      print();
    } else if (sum % 3 == 1) {
      getNumber(1, 2);
    } else {
      getNumber(2, 1);
    }
  } else {
    cout << -1;
  }
  return 0;
}
