#include <bits/stdc++.h>
using namespace std;
int N;
int phoneNum[2][9];
int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
bool in_bounds(int x, int y) {
  if (y == -2) {
    if (x == 0 && y == -2) return true;
    return false;
  }
  if (x < -1 || x > 1 || y > 1 || y < -2) return false;
  return true;
}
bool bounded(int n) {
  for (int i = 0; i < N; i++) {
    if (!in_bounds(phoneNum[0][i] + dx[n], phoneNum[1][i] + dy[n])) {
      return false;
    }
  }
  return true;
}
int main() {
  cin >> N;
  int temp;
  cin >> temp;
  for (int i = 0; i < N; i++) {
    int num = temp % 10;
    if (num == 0) {
      phoneNum[0][i] = 0;
      phoneNum[1][i] = -2;
    } else {
      (num % 3 != 0) ? phoneNum[0][i] = num % 3 - 2 : phoneNum[0][i] = 1;
      num--;
      phoneNum[1][i] = (num / 3 == 0) ? 1 : ((num / 3 == 1) ? 0 : -1);
    }
    temp /= 10;
  }
  for (int i = 0; i < 8; i++) {
    if (bounded(i)) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
