#include <bits/stdc++.h>
using namespace std;
map<long long, pair<long long, long long> > mp;
long long n;
string s;
long long dx[] = {1, 0, -1, 0};
long long dy[] = {0, 1, 0, -1};
vector<pair<long long, long long> > v;
bool ch(long long xx, long long yy) {
  for (long long i = 0; i < v.size(); i++) {
    long long x = v[i].first + xx;
    long long y = v[i].second + yy;
    if (x != 4 || y != 2) {
      if (1 > x || x > 3 || 1 > y || y > 3) return 0;
    }
  }
  return 1;
}
int main() {
  cin >> n >> s;
  for (long long i = 1; i <= 3; i++) {
    for (long long j = 1; j <= 3; j++) {
      mp[3 * (i - 1) + j] = {i, j};
    }
  }
  mp[0] = {4, 2};
  for (long long i = 0; i < n; i++) v.push_back(mp[s[i] - '0']);
  for (long long i = 0; i < 4; i++)
    if (ch(dx[i], dy[i])) return cout << "NO", 0;
  cout << "YES";
  return 0;
}
