#include <bits/stdc++.h>
using namespace std;
int A[20];
bool mark[20];
int main() {
  int n, lr = 20, lc = 20, mr = 0, mc = 0, r, c;
  char ch;
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> ch;
    A[i] = ch - '0';
  }
  for (long long int i = 1; i <= n; i++) {
    mark[A[i]] = 1;
    if (A[i] == 0) {
      r = 4;
      c = 2;
    } else {
      r = (A[i] - 1) / 3 + 1;
      c = (A[i] - 1) % 3 + 1;
    }
    if (r < lr) lr = r;
    if (r > mr) mr = r;
    if (c > mc) mc = c;
    if (c < lc) lc = c;
  }
  if (mr - lr == 3)
    cout << "YES"
         << "\n";
  else if (mr - lr <= 1 || mc - lc <= 1)
    cout << "NO"
         << "\n";
  else {
    if (mark[0])
      cout << "NO"
           << "\n";
    else if (mark[7] || mark[9])
      cout << "YES"
           << "\n";
    else
      cout << "NO"
           << "\n";
  }
}
