#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v;
string s;
int xx[10] = {3, 0, 0, 0, 1, 1, 1, 2, 2, 2};
int yy[10] = {1, 0, 1, 2, 0, 1, 2, 0, 1, 2};
vector<pair<int, int> > w;
bool ok(int i, int j);
bool fu(int a, int b);
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> s;
  v.resize(n);
  for (int i = 0; i < n; ++i) v[i] = int(s[i] - '0');
  w.resize(n);
  for (int i = 0; i < n; ++i) w[i] = make_pair(xx[v[i]], yy[v[i]]);
  int num = 0;
  for (int i = -3; i <= 3; ++i) {
    for (int j = -2; j <= 2; ++j) {
      num += int(fu(i, j));
    }
  }
  cout << (num == 1 ? "YES" : "NO");
  return 0;
}
bool ok(int i, int j) {
  if (i < 0 || i > 3) return false;
  if (j < 0 || j > 2) return false;
  if (i == 3 && j == 0) return false;
  if (i == 3 && j == 2) return false;
  return true;
}
bool fu(int a, int b) {
  for (int i = 0; i < n; ++i) {
    if (!ok(w[i].first + a, w[i].second + b)) return false;
  }
  return true;
}
