#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
};
int mat[4][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 500, 0, 501};
node pos(int n) {
  node ans;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      if (mat[i][j] == n) ans = {i, j};
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int a[n];
  for (int i = 0; i < n; i++) {
    a[i] = s[i] - '0';
  }
  node path[n - 1];
  for (int i = 0; i < n - 1; i++) {
    path[i] = {pos(a[i + 1]).x - pos(a[i]).x, pos(a[i + 1]).y - pos(a[i]).y};
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      if (mat[i][j] == 500 || mat[i][j] == 501 || mat[i][j] == a[0])
        continue;
      else {
        bool flow = 1;
        int xn = i;
        int yn = j;
        for (int k = 0; k < n - 1 && flow; k++) {
          xn += path[k].x;
          yn += path[k].y;
          if (xn < 0 || yn < 0 || xn >= 4 || yn >= 3 || (xn == 3 && yn == 2) ||
              (xn == 3 && yn == 0))
            flow = 0;
        }
        if (flow) {
          cout << "NO";
          return 0;
        }
      }
    }
  }
  cout << "YES";
  return 0;
}
