#include <bits/stdc++.h>
using namespace std;
int N, cnt = 0;
char a, b;
pair<int, int> c, d,
    A[10] = {make_pair(3, 1), make_pair(0, 0), make_pair(0, 1), make_pair(0, 2),
             make_pair(1, 0), make_pair(1, 1), make_pair(1, 2), make_pair(2, 0),
             make_pair(2, 1), make_pair(2, 2)};
vector<pair<int, int> > M;
bool valid(int i, int j) {
  return 0 <= i && i < 4 && 0 <= j && j < 3 && (i != 3 || j != 0) &&
         (i != 3 || j != 2);
}
bool check(int i, int j, int n) {
  if (n == N) return true;
  if (!valid(i, j)) return false;
  return check(i + M[n].first, j + M[n].second, n + 1);
}
int main() {
  scanf("%d\n", &N);
  scanf("%c", &a);
  if (N == 1) {
    printf("NO\n");
    return 0;
  }
  for (int i = 1; i < N; i++) {
    scanf("%c", &b);
    c = A[a - '0'];
    d = A[b - '0'];
    M.push_back(make_pair(d.first - c.first, d.second - c.second));
    a = b;
  }
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 3; j++)
      if (check(i, j, 0)) cnt++;
  cnt == 1 ? printf("YES\n") : printf("NO\n");
}
