#include <bits/stdc++.h>
using namespace std;
int a[50][50];
struct node {
  int x, y;
};
node c[50];
int main() {
  int n;
  scanf("%d", &n);
  char s[50];
  scanf("%s", s);
  int len = strlen(s);
  if (len == 1) {
    printf("NO\n");
  } else {
    for (int i = 1; i < len; i++) {
      int z = s[i - 1] - '0';
      int q = s[i] - '0';
      if (z == 0) {
        z = 11;
      }
      if (q == 0) {
        q = 11;
      }
      if ((q % 3) == (z % 3)) {
        c[i].y = 0;
        c[i].x = (q - 1) / 3 - (z - 1) / 3;
      } else {
        int y1 = (q % 3);
        int y2 = (z % 3);
        if (y1 == 0) y1 = 3;
        if (y2 == 0) y2 = 3;
        c[i].x = (q - 1) / 3 - (z - 1) / 3;
        c[i].y = (y2 - y1);
      }
    }
    int ans = 0;
    memset(a, -1, sizeof(a));
    for (int i = 1; i <= 3; i++) {
      for (int k = 1; k <= 3; k++) {
        a[i][k] = 1;
      }
    }
    a[4][2] = 1;
    for (int i = 1; i <= 3; i++) {
      for (int k = 1; k <= 3; k++) {
        int xx = i;
        int yy = k;
        int j;
        for (j = 1; j < len; j++) {
          int xxx = xx + c[j].x;
          int yyy = yy + c[j].y;
          if (a[xxx][yyy] == 1) {
            xx = xxx;
            yy = yyy;
          } else
            break;
        }
        if (j == len) ans++;
      }
    }
    int xx = 4;
    int yy = 2;
    int j;
    for (j = 1; j < len; j++) {
      int xxx = xx + c[j].x;
      int yyy = yy + c[j].y;
      if (a[xxx][yyy] == 1) {
        xx = xxx;
        yy = yyy;
      } else
        break;
    }
    if (j == len) ans++;
    if (ans == 1) {
      printf("YES\n");
    } else
      printf("NO\n");
  }
}
