#include <bits/stdc++.h>
using namespace std;
long long int pows(long long int a, long long int n, long long int m) {
  long long int res = 1;
  while (n) {
    if (n % 2 != 0) {
      res = (res * a) % m;
      n--;
    } else {
      a = (a * a) % m;
      n = n / 2;
    }
  }
  return res % m;
}
void solve(int a[], int n) {
  int b[11];
  for (int i = 0; i <= 9; i++) {
    b[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    b[a[i]]++;
  }
  if (b[0] == n) {
    cout << 0 << endl;
    return;
  } else if (n == 1 && a[0] == 0) {
    cout << 0 << endl;
  } else if (n == 1 && a[0] != 0) {
    cout << -1 << endl;
  } else {
    long long int sum = 0;
    int flag = 0;
    int pos;
    for (int i = 0; i < n; i++) {
      sum = sum + a[i];
      if (a[i] == 0) {
        flag = 1;
        pos = i;
      }
    }
    if (flag == 0) {
      cout << -1 << endl;
    } else {
      int g = 0;
      sort(a, a + n);
      int p = sum % 3;
      if (p == 1) {
        if (b[1] >= 1) {
          b[1]--;
          g = 1;
        } else if (b[4] >= 1) {
          b[4]--;
          g = 1;
        } else if (b[7] >= 1) {
          b[7]--;
          g = 1;
        } else if (b[2] >= 2) {
          b[2] = b[2] - 2;
          g = 1;
        } else if (b[2] >= 1 && b[5] >= 1) {
          b[2]--;
          b[5]--;
          g = 1;
        } else if (b[6] >= 1 && b[1] >= 1) {
          b[6]--;
          b[1]--;
        }
      }
      if (p == 2) {
        if (b[2] >= 1) {
          b[2]--;
          g = 1;
        } else if (b[5] >= 1) {
          b[5]--;
          g = 1;
        } else if (b[8] >= 1) {
          b[8]--;
          g = 1;
        } else if (b[1] >= 2) {
          b[1] = b[1] - 2;
          g = 1;
        } else if (b[4] >= 2) {
          b[4] = b[4] - 2;
          g = 1;
        } else if (b[4] >= 1 && b[1] >= 1) {
          b[4]--;
          b[1]--;
          g = 1;
        } else if (b[7] >= 1 && b[1] >= 1) {
          b[7]--;
          b[1]--;
          g = 1;
        }
      }
      if (g == 1) {
        int f = 0;
        for (int i = 9; i >= 1; i--) {
          if (b[i] != 0) {
            f = 1;
          }
        }
        if (f == 1) {
          for (int i = 9; i >= 0; i--) {
            for (int k = 0; k < b[i]; k++) {
              cout << i;
            }
          }
        } else {
          cout << 0 << endl;
        }
      } else
        cout << -1 << endl;
      cout << endl;
    }
  }
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
bool isprime(long long int n) {
  if (n == 1) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  bool flag1 = 0;
  int sum = 0;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    sum += v[i];
    if (v[i] == 0) {
      flag1 = 1;
    }
  }
  if (flag1 == 0) {
    cout << -1;
  } else {
    sort(v.begin(), v.end());
    int x = sum % 3;
    int i = 0;
    while (sum % 3 != 0) {
      while (i < v.size()) {
        if (v[i] % 3 == x) {
          sum -= v[i];
          v.erase(v.begin() + i);
          if (sum % 3 == 0) break;
        } else {
          i++;
        }
      }
      if (sum % 3 != 0) {
        if (x == 1)
          x++;
        else
          x--;
        i = 0;
      }
    }
    reverse(v.begin(), v.end());
    if (v[0] == 0) {
      cout << 0;
    } else {
      for (int i = 0; i < v.size(); i++) {
        cout << v[i];
      }
    }
  }
}
