#include <bits/stdc++.h>
using namespace std;
int v[3][3];
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  v[1][1] = 1;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') {
      v[2][0] = 1;
      v[2][2] = 1;
      v[2][1] = 1;
      v[1][0] = 1;
      v[1][2] = 1;
    }
    if (s[i] == '1') {
      v[0][0] = 1;
      v[0][1] = 1;
      v[0][2] = 1;
      v[1][0] = 1;
      v[2][0] = 1;
    }
    if (s[i] == '2') {
      v[0][0] = 1;
      v[0][1] = 1;
      v[0][2] = 1;
    }
    if (s[i] == '3') {
      v[2][2] = 1;
      v[0][2] = 1;
      v[1][2] = 1;
      v[0][0] = 1;
      v[0][1] = 1;
    }
    if (s[i] == '4') {
      v[0][0] = 1;
      v[1][0] = 1;
      v[2][0] = 1;
    }
    if (s[i] == '6') {
      v[0][2] = 1;
      v[1][2] = 1;
      v[2][2] = 1;
    }
    if (s[i] == '7') {
      v[2][0] = 1;
      v[2][1] = 1;
      v[1][0] = 1;
      v[0][0] = 1;
    }
    if (s[i] == '8') {
      v[0][2] = 1;
      v[2][2] = 1;
    }
    if (s[i] == '9') {
      v[0][2] = 1;
      v[2][2] = 1;
      v[1][2] = 1;
      v[2][1] = 1;
    }
  }
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      if (v[i][j] == 0) {
        cout << "NO";
        return 0;
      }
    }
  cout << "YES";
  return 0;
}
