#include <bits/stdc++.h>
using namespace std;
int n;
string s;
pair<int, int> conv[] = {make_pair(3, 1), make_pair(0, 0), make_pair(0, 1),
                         make_pair(0, 2), make_pair(1, 0), make_pair(1, 1),
                         make_pair(1, 2), make_pair(2, 0), make_pair(2, 1),
                         make_pair(2, 2)};
bool isval(int x, int y) {
  bool found = false;
  for (int i = 0; i < 10; ++i)
    if (conv[i] == make_pair(x, y)) found = true;
  return found;
}
vector<pair<int, int> > v;
int main() {
  cin >> n >> s;
  for (int i = 0; i < s.length(); ++i) {
    v.push_back(conv[s[i] - '0']);
  }
  int cnt = 0;
  for (int i = -2; i < 2; ++i) {
    for (int j = -3; j < 3; ++j) {
      bool valid = true;
      for (int k = 0; k < v.size(); ++k) {
        int dx = v[k].first + i;
        int dy = v[k].second + j;
        if (!isval(dx, dy)) {
          valid = false;
          break;
        }
      }
      if (valid) cnt++;
    }
  }
  if (cnt == 1)
    printf("YES\n");
  else
    printf("NO\n");
}
