#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); }
vector<int> dx, dy;
int n;
bool dfs(int x, int y, int i) {
  if (i == n) return true;
  if (x < 0 || y < 0 || x > 3 || (x == 3 && y != 1) || (y >= 3))
    return false;
  else
    return dfs(x + dx[i], y + dy[i], i + 1);
}
int main() {
  cin >> n;
  dx.resize(n - 1);
  dy.resize(n - 1);
  map<int, pair<int, int> > key;
  key[0] = make_pair(3, 1);
  key[1] = make_pair(0, 0);
  key[2] = make_pair(0, 1);
  key[3] = make_pair(0, 2);
  key[4] = make_pair(1, 0);
  key[5] = make_pair(1, 1);
  key[6] = make_pair(1, 2);
  key[7] = make_pair(2, 0);
  key[8] = make_pair(2, 1);
  key[9] = make_pair(2, 2);
  string s;
  cin >> s;
  pair<int, int> last = key[s[0] - '0'];
  for (int i = 1, j = 0; i < s.size(); ++j, ++i) {
    pair<int, int> cur = key[s[i] - '0'];
    dx[j] = cur.first - last.first;
    dy[j] = cur.second - last.second;
    last = cur;
  }
  if (n == 1) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 0; i <= 9; ++i) {
    if (i != s[0] - '0') {
      bool ch = dfs(key[i].first, key[i].second, 0);
      if (ch == true) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
}
