#include <bits/stdc++.h>
using namespace std;
int n;
string d;
int pos[10][2] = {{3, 1}, {0, 0}, {0, 1}, {0, 2}, {1, 0},
                  {1, 1}, {1, 2}, {2, 0}, {2, 1}, {2, 2}};
int drc[10][2];
inline bool valid(int x, int y) {
  return ((x >= 0 && x <= 2) && (y >= 0 && y <= 2)) || (x == 3 && y == 1);
}
bool check(int x, int y) {
  for (int i = 0; i < 10; ++i) {
    if (pos[i][0] == x && pos[i][1] == y) continue;
    int sx = pos[i][0], sy = pos[i][1];
    bool succ = true;
    for (int j = 0; j < n - 1; ++j) {
      sx += drc[j][0];
      sy += drc[j][1];
      succ = succ && valid(sx, sy);
      if (!succ) break;
    }
    if (succ) return false;
  }
  return true;
}
int main() {
  cin >> n >> d;
  for (int i = 1; i < n; ++i) {
    drc[i - 1][0] = pos[d[i] - '0'][0] - pos[d[i - 1] - '0'][0];
    drc[i - 1][1] = pos[d[i] - '0'][1] - pos[d[i - 1] - '0'][1];
  }
  if (check(pos[d[0] - '0'][0], pos[d[0] - '0'][1])) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
