#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
int x[] = {3, 0, 0, 0, 1, 1, 1, 2, 2, 2};
int y[] = {1, 0, 1, 2, 0, 1, 2, 0, 1, 2};
bool in_range(int x, int y) {
  if (x == 3) return y == 1;
  return x >= 0 && x <= 2 && y <= 2 && y >= 0;
}
int main() {
  ios::sync_with_stdio(false);
  string s;
  int n;
  cin >> n;
  cin >> s;
  for (int i = 0; i < 4; i++) {
    bool ok = 1;
    for (int j = 0; j < n; j++) {
      int t = s[j] - '0';
      if (!in_range(x[t] + dx[i], y[t] + dy[i])) ok = 0;
    }
    if (ok) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
