#include <bits/stdc++.h>
using namespace std;
pair<int, int> pos[10];
pair<int, int> dir[100];
pair<int, int> operator-(pair<int, int> x, pair<int, int> y) {
  return make_pair(x.first - y.first, x.second - y.second);
}
pair<int, int> operator+(pair<int, int> x, pair<int, int> y) {
  return make_pair(x.first + y.first, x.second + y.second);
}
bool isInside(pair<int, int> x) {
  return (x.first <= 3 && x.first > 0 && x.second <= 3 && x.second >= 1) ||
         x == (make_pair(4, 2));
}
int main(int argc, char** argv) {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt = 1;
  for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
      pos[cnt] = make_pair(i, j);
      cnt++;
    }
  }
  pos[0] = make_pair(4, 2);
  for (int i = 1; i < n; i++) {
    dir[i] = pos[s[i] - '0'] - pos[s[i - 1] - '0'];
  }
  if (n == 1) {
    cout << "NO";
    return 0;
  }
  int times = 0;
  for (int i = 0; i <= 9; i++) {
    bool isOk = true;
    pair<int, int> curPos = pos[i];
    for (int j = 0; j < n; j++) {
      curPos = curPos + dir[j];
      if (!isInside(curPos)) isOk = false;
    }
    if (isOk) times++;
  }
  if (times == 1)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
