#include <bits/stdc++.h>
using namespace std;
int a[4][3];
pair<int, int> f(int cur, int next) {
  pair<int, int> f, s;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      if (cur == a[i][j]) {
        f = make_pair(i, j);
      }
      if (next == a[i][j]) {
        s = make_pair(i, j);
      }
    }
  }
  return make_pair(s.first - f.first, s.second - f.second);
}
pair<int, int> find_pos(int cur) {
  pair<int, int> f, s;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      if (cur == a[i][j]) {
        return make_pair(i, j);
      }
    }
  }
}
bool correct_pos(pair<int, int> p) {
  if (p.first >= 0 && p.first <= 2 && p.second >= 0 && p.second <= 2) {
    return true;
  }
  if (p.first == 3 && p.second == 1) {
    return true;
  }
  return false;
}
string s;
bool correct(vector<pair<int, int>> &v) {
  for (int i = 0; i <= 9; i++) {
    if (s[0] - '0' == i) continue;
    pair<int, int> pos = find_pos(i);
    bool flag = true;
    for (int j = 0; j < v.size(); j++) {
      if (!correct_pos(
              make_pair(pos.first + v[j].first, pos.second + v[j].second))) {
        flag = false;
        break;
      }
      pos = make_pair(pos.first + v[j].first, pos.second + v[j].second);
    }
    if (flag) {
      return true;
    }
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  cin >> s;
  int qq = 1;
  vector<pair<int, int>> v;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      a[i][j] = qq++;
    }
  }
  a[3][0] = a[3][2] = -1;
  a[3][1] = 0;
  for (int i = 0; i < n - 1; i++) {
    v.push_back(f(s[i] - '0', s[i + 1] - '0'));
  }
  if (correct(v)) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
  return 0;
}
