#include <bits/stdc++.h>
using namespace std;
int loc[10][2] = {{4, 2}, {1, 1}, {1, 2}, {1, 3}, {2, 1},
                  {2, 2}, {2, 3}, {3, 1}, {3, 2}, {3, 3}};
bool vis[10];
char input[10];
int main() {
  int n, i, j, maxx, maxy, minx, miny, cunt, mark;
  scanf("%d", &n);
  scanf("%s", input);
  maxx = maxy = 0;
  minx = miny = 4;
  for (i = 0; i < n; i++) {
    j = input[i] - '0';
    maxx = max(maxx, loc[j][0]);
    minx = min(minx, loc[j][0]);
    maxy = max(maxy, loc[j][1]);
    miny = min(miny, loc[j][1]);
  }
  cunt = 0;
  if ((maxx - minx >= 2) && (maxy - miny == 2)) {
    if (maxx - minx == 2) {
      for (i = 0; i < n; i++) {
        j = input[i] - '0';
        if (loc[j][0] == maxx) {
          mark = j;
          if (vis[j] == false) {
            vis[j] = true;
            cunt++;
          }
        }
      }
      if (cunt == 1 && (mark == 8 || mark == 0))
        printf("NO");
      else
        printf("YES");
    } else
      printf("YES");
  } else if (maxx - minx == 3)
    printf("YES");
  else
    printf("NO");
  return 0;
}
