#include <bits/stdc++.h>
const double PI = 3.141592653589793238460;
using namespace std;
vector<int> d;
vector<int> l;
vector<int> r;
vector<int> u;
bool isPossibleL(string st) {
  for (char ch : st) {
    for (int n : l)
      if (ch - '0' == n) return false;
  }
  return true;
}
bool isPossibleR(string st) {
  for (char ch : st) {
    for (int n : r)
      if (ch - '0' == n) return false;
  }
  return true;
}
bool isPossibleU(string st) {
  for (char ch : st) {
    for (int n : u)
      if (ch - '0' == n) return false;
  }
  return true;
}
bool isPossibleD(string st) {
  for (char ch : st) {
    for (int n : d)
      if (ch - '0' == n) return false;
  }
  return true;
}
int main() {
  l.push_back(1), l.push_back(4), l.push_back(7), l.push_back(0);
  r.push_back(3), r.push_back(6), r.push_back(9), r.push_back(0);
  d.push_back(7), d.push_back(0), d.push_back(9);
  u.push_back(1), u.push_back(2), u.push_back(3);
  int n;
  string st;
  cin >> n >> st;
  if (isPossibleL(st) || isPossibleR(st) || isPossibleU(st) || isPossibleD(st))
    cout << "NO";
  else
    cout << "YES";
}
