#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int b[10];
  for (int i = 0; i < 10; i++) {
    b[i] = 0;
  }
  int temp;
  cin >> temp;
  for (int i = 0; i < n; i++) {
    a[i] = temp % 10;
    temp /= 10;
    b[a[i]] = 1;
  }
  if (((b[1] + b[4] + b[7]) * (b[3] + b[6] + b[9]) != 0) &&
          (((b[7] + b[9]) * (b[1] + b[2] + b[3]) != 0) ||
           (b[8] && (b[7] || b[9]) && (b[1] || b[2] || b[3]))) ||
      (b[0] && (b[1] || b[2] || b[3]))) {
    cout << "YES";
  } else
    cout << "NO";
  return 0;
}
