#include <bits/stdc++.h>
using namespace std;
const int keypad[4][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {-1, 0, -1}};
struct Vector {
  int x, y;
};
int main() {
  int n;
  string s;
  cin >> n >> s;
  Vector sum[n - 1];
  for (int i = 0; i < n - 1; i++) {
    int i_x = (s[i] - '0' - 1) / 3, i_y = (s[i] - '0' - 1) % 3;
    int f_x = (s[i + 1] - '0' - 1) / 3, f_y = (s[i + 1] - '0' - 1) % 3;
    if (s[i] - '0' == 0) {
      i_x = 3;
      i_y = 1;
    }
    if (s[i + 1] - '0' == 0) {
      f_x = 3;
      f_y = 1;
    }
    sum[i].x = f_x - i_x;
    sum[i].y = f_y - i_y;
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      if (keypad[i][j] == s[0] - '0') continue;
      int d_x = i, d_y = j;
      for (int k = 0; k < n - 1; k++) {
        d_x = d_x + sum[k].x, d_y = d_y + sum[k].y;
        if (d_x < 0 || d_x > 3 || d_y < 0 || d_y > 2 || keypad[d_x][d_y] == -1)
          break;
      }
      if (d_x >= 0 && d_x < 4)
        if (d_y >= 0 && d_y < 3) {
          if (keypad[d_x][d_y] == -1 || keypad[i][j] == -1) continue;
          cout << "NO" << endl;
          return 0;
        }
    }
  }
  cout << "YES" << endl;
  return 0;
}
