#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string q;
  int z;
  cin >> q;
  int a[5][5] = {0};
  for (int i = 0; i < n; i++) {
    z = q[i] - '0';
    if (z == 0) {
      a[4][2] = 1;
    } else {
      a[(z - 1) / 3 + 1][(z - 1) % 3 + 1] = 1;
    }
  }
  int mx = 0;
  int nx = 10;
  int my = 0;
  int ny = 10;
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= 3; j++) {
      if (a[i][j] == 1) {
        if (i > mx) mx = i;
        if (i < nx) nx = i;
        if (j > my) my = j;
        if (j < ny) ny = j;
      }
    }
  }
  bool f = true;
  if (mx - nx == 3) {
    f = false;
  } else if (mx - nx < 2 || my - ny < 2) {
    f = true;
  } else {
    int k = 0;
    for (int i = 1; i <= 3; i++) {
      k = k + a[mx][i];
    }
    if (k == 1 && a[mx][2] == 1) {
      f = true;
    } else {
      f = false;
    }
  }
  if (!f)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
