#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
pair<int, int> pos[20];
int n;
string s;
vector<pair<int, int>> v;
bool isvalid(int x, int y) {
  if ((x >= 1 && x <= 3) && (y >= 1 && y <= 3)) return true;
  if (x == 4 && y == 2) return true;
  return false;
}
bool check(int x, int y) {
  if (!isvalid(x, y)) return false;
  for (auto p : v) {
    x += p.first;
    y += p.second;
    if (!isvalid(x, y)) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int ptr = 1;
  for (int i = 1; i <= 3; ++i) {
    for (int j = 1; j <= 3; ++j) {
      pos[ptr].first = i;
      pos[ptr].second = j;
      ptr++;
    }
  }
  pos[0].first = 4, pos[0].second = 2;
  cin >> n >> s;
  if (n == 1) {
    cout << "NO" << '\n';
    return 0;
  }
  int sx = pos[s[0] - '0'].first, sy = pos[s[0] - '0'].second;
  for (int i = 1; i < n; ++i) {
    int x = pos[s[i] - '0'].first, y = pos[s[i] - '0'].second;
    int dx = x - sx;
    int dy = y - sy;
    v.emplace_back(dx, dy);
    sx = x;
    sy = y;
  }
  int cnt = 0;
  for (int d = 0; d <= 9; ++d) {
    if (check(pos[d].first, pos[d].second)) ++cnt;
  }
  if (cnt == 1)
    cout << "YES" << '\n';
  else
    cout << "NO" << '\n';
}
