#include <bits/stdc++.h>
using namespace std;
int main() {
  int A[4][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9, -1, 0, -1};
  int n;
  string input, column, row;
  cin >> n >> input;
  int size = input.size(), z;
  for (z = 0; z < size; z++)
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 3; j++)
        if (input[z] - '0' == A[i][j]) {
          row += to_string(i);
          column += to_string(j);
        }
  bool flag1, flag2, flag3, flag4;
  flag1 = flag2 = flag3 = flag4 = 0;
  size = row.size();
  for (z = 0; z < size; z++) {
    if (flag1 != 1 && row[z] + 1 > '3' ||
        (row[z] + 1 == '3' && column[z] != '1'))
      flag1 = 1;
    if (flag2 != 1 && row[z] - 1 < '0') flag2 = 1;
    if (flag3 != 1 && column[z] + 1 > '2' ||
        (row[z] == '3' && column[z] + 1 != '1'))
      flag3 = 1;
    if (flag4 != 1 && column[z] - 1 < '0' ||
        (row[z] == '3' && column[z] - 1 != '1'))
      flag4 = 1;
  }
  (flag1 && flag2 && flag3 && flag4) ? cout << "YES" : cout << "NO";
}
