#include <bits/stdc++.h>
using namespace std;
int tell[4][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {-1, 0, -1}};
int x[4] = {-1, 1, 0, 0};
int y[4] = {0, 0, -1, 1};
vector<pair<int, int> > v;
void findcord(int num) {
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 3; j++)
      if (tell[i][j] == num) {
        v.push_back(make_pair(i, j));
        return;
      }
}
bool checkavi(int xx, int yy) {
  if (xx < 0 || xx > 3 || yy < 0 || yy > 2 || tell[xx][yy] == -1) return true;
  return false;
}
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    findcord(s[i] - 48);
  }
  bool avi = true;
  for (int cord = 0; cord < 4; cord++) {
    avi = true;
    for (int i = 0; i < s.length(); i++) {
      if (checkavi(v[i].first - x[cord], v[i].second - y[cord])) {
        avi = false;
        break;
      }
    }
    if (avi) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
