#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> arr;
  int number;
  cin >> number;
  int aux;
  while (n != 0) {
    aux = number % 10;
    number /= 10;
    arr.push_back(aux);
    n--;
  }
  for (int i = 0; i < arr.size(); i++) {
    for (int j = 0; j < arr.size(); j++) {
      if (arr[j] == arr[i] && j != i) arr.erase(arr.begin() + j);
    }
  }
  bool xl1 = false;
  bool xl2 = false;
  bool xl3 = false;
  bool yl1 = false;
  bool yl2 = false;
  bool yl3 = false;
  bool allXline = false;
  bool allYline = false;
  bool especial = false;
  bool middle = false;
  bool justEight;
  for (int i = 0; i < arr.size(); i++) {
    if (arr[i] == 1 || arr[i] == 2 || arr[i] == 3) xl1 = true;
    if (arr[i] == 4 || arr[i] == 5 || arr[i] == 6) xl2 = true;
    if (arr[i] == 7 || arr[i] == 8 || arr[i] == 9) xl3 = true;
    if (arr[i] == 1 || arr[i] == 4 || arr[i] == 7) yl1 = true;
    if (arr[i] == 2 || arr[i] == 5 || arr[i] == 8) yl2 = true;
    if (arr[i] == 3 || arr[i] == 6 || arr[i] == 9) yl3 = true;
    if (arr[i] == 5) middle = true;
    if (arr[i] == 0) especial = true;
    if (arr[i] == 8) {
      justEight = true;
      for (int j = 0; j < arr.size(); j++) {
        if (arr[j] == 7 || arr[j] == 9) justEight = false;
      }
    }
    if (especial && xl1) {
      cout << "YES";
      goto a;
    }
    if (xl1 && yl1 && yl3 && xl3) {
      if (justEight) {
        continue;
      } else {
        cout << "YES";
        goto a;
      }
    }
  }
  cout << "NO";
a:
  return 0;
}
