#include <bits/stdc++.h>
using namespace std;
string arr;
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];
  }
}
int main() {
  char ch;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ch;
    arr += ch;
    sum += (ch - 48);
  }
  sort(arr.rbegin(), arr.rend());
  if (arr[n - 1] == '0') {
    if (sum % 3 == 0) {
      print();
    } else {
      int a1 = -1, b1 = -1, c2 = -1, d2 = -1;
      for (int i = n - 1; i >= 0; i--) {
        if ((arr[i] - 48) % 3 == 1) {
          if (a1 == -1)
            a1 = arr[i] - 48;
          else if (b1 == -1)
            b1 = arr[i] - 48;
        } else if ((arr[i] - 48) % 3 == 2) {
          if (c2 == -1)
            c2 = arr[i] - 48;
          else if (d2 == -1)
            d2 = arr[i] - 48;
        }
        if (a1 != -1 && b1 != -1 && c2 != -1 && d2 != -1) break;
      }
      if (sum % 3 == 1 && a1 != -1) {
        sum -= a1;
        print(a1);
      } else if (sum % 3 == 1 && c2 != -1 && d2 != -1) {
        sum -= c2;
        sum -= d2;
        print(c2, d2);
      } else if (sum % 3 == 2 && c2 != -1) {
        sum -= c2;
        print(c2);
      } else if (sum % 3 == 2 && a1 != -1 && b1 != -1) {
        sum -= a1;
        sum -= b1;
        print(a1, b1);
      } else {
        cout << -1;
      }
    }
  } else {
    cout << -1;
  }
  return 0;
}
