#include <bits/stdc++.h>
using namespace std;
long long d[200][200];
int main() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  vector<long long> v;
  for (long long i = (0); i < (s.size()); ++i) {
    v.push_back(s[i] - '0');
  }
  vector<pair<long long, long long> > v1;
  v1.push_back(make_pair(3, 1));
  v1.push_back(make_pair(0, 0));
  v1.push_back(make_pair(0, 1));
  v1.push_back(make_pair(0, 2));
  v1.push_back(make_pair(1, 0));
  v1.push_back(make_pair(1, 1));
  v1.push_back(make_pair(1, 2));
  v1.push_back(make_pair(2, 0));
  v1.push_back(make_pair(2, 1));
  v1.push_back(make_pair(2, 2));
  vector<pair<long long, long long> > v2;
  for (long long i = (0); i < (v.size()); ++i) {
    v2.push_back(v1[v[i]]);
  }
  long long c = 0;
  for (long long y = (-5); y < (5); ++y) {
    for (long long x = (-5); x < (5); ++x) {
      memset((d), (-1), sizeof(d));
      d[100 + 0][100 + 0] = 0;
      d[100 + 0][100 + 1] = 0;
      d[100 + 0][100 + 2] = 0;
      d[100 + 1][100 + 0] = 0;
      d[100 + 1][100 + 1] = 0;
      d[100 + 1][100 + 2] = 0;
      d[100 + 2][100 + 0] = 0;
      d[100 + 2][100 + 1] = 0;
      d[100 + 2][100 + 2] = 0;
      d[100 + 3][100 + 1] = 0;
      int flag = 1;
      for (long long i = (0); i < (v2.size()); ++i) {
        if (d[y + 100 + v2[i].first][x + 100 + v2[i].second] == -1) {
          flag = 0;
        }
      }
      if (flag == 1) c++;
    }
  }
  if (c == 1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
