#include <bits/stdc++.h>
using namespace std;
char vis[25][25];
int main() {
  int Case = 1;
  int n, m, k;
  string s;
  char dump[2];
  while (cin >> n >> s) {
    map<char, pair<int, int> > make_pair;
    for (int i = 0; i < 25; i++) {
      for (int j = 0; j < 25; j++) {
        vis[i][j] = '*';
      }
    }
    make_pair['1'] = pair<int, int>(1, 1);
    vis[1][1] = '1';
    make_pair['2'] = pair<int, int>(1, 2);
    vis[1][2] = '2';
    make_pair['3'] = pair<int, int>(1, 3);
    vis[1][3] = '3';
    make_pair['4'] = pair<int, int>(2, 1);
    vis[2][1] = '4';
    make_pair['5'] = pair<int, int>(2, 2);
    vis[2][2] = '5';
    make_pair['6'] = pair<int, int>(2, 3);
    vis[2][3] = '6';
    make_pair['7'] = pair<int, int>(3, 1);
    vis[3][1] = '7';
    make_pair['8'] = pair<int, int>(3, 2);
    vis[3][2] = '8';
    make_pair['9'] = pair<int, int>(3, 3);
    vis[3][3] = '9';
    make_pair['0'] = pair<int, int>(4, 2);
    vis[4][2] = '0';
    vector<pair<int, int> > v;
    for (int i = 1; i < s.size(); i++) {
      int F = make_pair[s[i]].first - make_pair[s[i - 1]].first;
      int S = make_pair[s[i]].second - make_pair[s[i - 1]].second;
      v.push_back(pair<int, int>(F, S));
    }
    bool possible = false;
    for (char ch = '0'; ch <= '9'; ch++) {
      int F = make_pair[ch].first;
      int S = make_pair[ch].second;
      string t;
      t += ch;
      bool pos = true;
      for (int i = 0; i < v.size(); i++) {
        F += v[i].first;
        S += v[i].second;
        if (F >= 1 && S >= 1 && vis[F][S] != '*') {
          t += vis[F][S];
        }
      }
      if ((int)t.size() == (int)s.size() && t != s) {
        possible = true;
        break;
      }
    }
    if (possible)
      puts("NO");
    else
      puts("YES");
  }
  return 0;
}
