#include <bits/stdc++.h>
using namespace std;
int n;
const int dir[4][10] = {{8, -1, -1, -1, 1, 2, 3, 4, 5, 6},
                        {-1, 2, 3, -1, 5, 6, -1, 8, 9, -1},
                        {-1, 4, 5, 6, 7, 8, 9, -1, 0, -1},
                        {-1, -1, 1, 2, -1, 4, 5, -1, 7, 8}};
char s[9];
int main() {
  int i, j;
  scanf("%d%s", &n, s);
  for (i = 0; i < 4; i++) {
    for (j = 0; j < n; j++) {
      int t = s[j] - '0';
      if (dir[i][t] == -1) break;
    }
    if (j >= n) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}
