#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
const unsigned long long N = 200000000;
const long long INFll = 1ll * INF * INF;
const long double ldINF = 1e+018;
const long double EPS = 0.000000001;
const int sdx[4] = {-1, 0, 1, 0};
const int sdy[4] = {0, 1, 0, -1};
template <typename T>
ostream& operator<<(ostream& out, pair<T, T>& a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T>
istream& operator>>(istream& in, pair<T, T>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T>
istream& operator>>(istream& in, vector<T>& a) {
  for (int i = 0; i < a.size(); ++i) in >> a[i];
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> a) {
  for (int i = 0; i < a.size(); ++i)
    if (i == a.size() - 1)
      out << a[i];
    else
      out << a[i] << " ";
  return out;
}
string s[5];
vector<pair<int, int> > v;
bool check(int x, int y) {
  for (int i = 0; i < v.size(); i++) {
    x += v[i].first, y += v[i].second;
    if (x < 0 || x > 3 || y < 0 || y > 2 || s[x][y] == '-') return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  s[0] = "123";
  s[1] = "456";
  s[2] = "789";
  s[3] = "-0-";
  int n;
  cin >> n;
  string a;
  cin >> a;
  int x, y;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 3; j++)
      if (s[i][j] == a[0]) x = i, y = j;
  int x1 = x, y1 = y;
  for (int z = 0; z < n - 1; z++) {
    bool f = false;
    for (int i = 0; i < 4 && !f; i++)
      for (int j = 0; j < 3 && !f; j++)
        if (s[i][j] == a[z + 1]) {
          f = true;
          v.push_back(make_pair(i - x, j - y));
          x = i, y = j;
        }
  }
  x = x1, y = y1;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 3; j++) {
      if (s[i][j] == '-' || (x == i && y == j)) continue;
      if (check(i, j)) {
        cout << "NO\n";
        return 0;
      }
    }
  cout << "YES\n";
  if (0)
    cerr << fixed << setprecision(0)
         << "TIME = " << clock() / (long double)CLOCKS_PER_SEC * 1000 << "\n";
  return 0;
}
