#include <bits/stdc++.h>
int posx[10], posy[10], vetx[20], vety[20], n;
bool isvalid(int i, int j) {
  if (i >= 0 && i < 3 && j >= 0 && j < 3) return true;
  if (i == 1 && j == 3) return true;
  return false;
}
bool simulate(int x, int y, int p) {
  if (p == n)
    return true;
  else if (!isvalid(x, y))
    return false;
  else
    return simulate(x + vetx[p], y + vety[p], p + 1);
}
int main() {
  char str[20], seq[20];
  scanf("%d %s", &n, str);
  for (int i = 0; i < n; i++) {
    seq[i] = str[i] - '0';
  }
  posx[0] = 1;
  posy[0] = 3;
  posx[1] = 0;
  posy[1] = 0;
  posx[2] = 1;
  posy[2] = 0;
  posx[3] = 2;
  posy[3] = 0;
  posx[4] = 0;
  posy[4] = 1;
  posx[5] = 1;
  posy[5] = 1;
  posx[6] = 2;
  posy[6] = 1;
  posx[7] = 0;
  posy[7] = 2;
  posx[8] = 1;
  posy[8] = 2;
  posx[9] = 2;
  posy[9] = 2;
  for (int i = 1; i < n; i++) {
    vetx[i - 1] = posx[seq[i]] - posx[seq[i - 1]];
    vety[i - 1] = posy[seq[i]] - posy[seq[i - 1]];
  }
  vetx[n - 1] = 0;
  vety[n - 1] = 0;
  bool repetitive = false;
  for (int i = 0; i < 10 && !repetitive; i++) {
    if (i == seq[0]) continue;
    if (simulate(posx[i], posy[i], 0)) repetitive = true;
  }
  if (repetitive)
    printf("NO\n");
  else
    printf("YES\n");
  return 0;
}
