#include <bits/stdc++.h>
using namespace std;
int a[][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9, -1, 0, -1};
char h[101];
int main() {
  int q, w, e, r, t, sum = 0;
  int e1, r1, c, v, c1, v1;
  cin >> q;
  cin >> h;
  for (e = 0; e < 4; e++) {
    for (r = 0; r < 3; r++) {
      e1 = e;
      r1 = r;
      if (a[e1][r1] == -1) {
        continue;
      }
      for (w = 1; w < q; w++) {
        for (c = 0; c < 4; c++) {
          for (v = 0; v < 3; v++) {
            if (a[c][v] == h[w - 1] - 48) {
              goto st;
            }
          }
        }
      st:
        c1 = c;
        v1 = v;
        for (c = 0; c < 4; c++) {
          for (v = 0; v < 3; v++) {
            if (a[c][v] == h[w] - 48) {
              goto st2;
            }
          }
        }
      st2:
        e1 += c - c1;
        r1 += v - v1;
        if (!(((0 <= e1) && (e1 < 4)) && ((0 <= r1) && (r1 < 3)))) {
          goto miss;
        }
        if (a[e1][r1] == -1) {
          goto miss;
        }
      }
      sum++;
    miss:;
    }
  }
  if (sum > 1) {
    cout << "NO";
  } else {
    cout << "YES";
  }
  return 0;
}
