#include <bits/stdc++.h>
using namespace std;
int p[20][20];
int x[15], y[15];
int main(void) {
  int i, j, k;
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  for (i = 0; i <= 19; i++) {
    for (j = 0; j <= 9; j++) {
      p[i][j] = -1;
    }
  }
  p[1][1] = 1;
  p[1][2] = 2;
  p[1][3] = 3;
  p[2][1] = 4;
  p[2][2] = 5;
  p[2][3] = 6;
  p[3][1] = 7;
  p[3][2] = 8;
  p[3][3] = 9;
  p[4][2] = 0;
  int n;
  string s;
  cin >> n >> s;
  if (n == 1) {
    cout << "NO" << endl;
    return 0;
  }
  for (i = 0; i < n; i++) {
    int d = s[i] - '0';
    int a, b;
    for (j = 1; j <= 4; j++) {
      for (k = 1; k <= 3; k++) {
        if (p[j][k] == d) {
          a = j;
          b = k;
          break;
        }
      }
    }
    x[i] = a;
    y[i] = b;
  }
  int c = 0;
  for (i = 1; i <= 4; i++) {
    for (j = 1; j <= 3; j++) {
      if (i == 4 && (j == 1 || j == 3)) continue;
      bool f = true;
      for (k = 1; k < n; k++) {
        int dx = i + x[k] - x[0];
        int dy = j + y[k] - y[0];
        if (!(dx >= 1 && dx <= 4 && dy >= 1 && dy <= 3 && p[dx][dy] != -1)) {
          f = false;
        }
      }
      if (f) c++;
    }
  }
  if (c >= 2)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
  return 0;
}
