#include <bits/stdc++.h>
using namespace std;
int main() {
  char ligit[10];
  int n;
  int len = 1, xuong = 1, trai = 1, phai = 1;
  cin >> n;
  cin >> ligit;
  for (int i = 0; i < strlen(ligit); i++) {
    if (ligit[i] == '0' || ligit[i] == '9' || ligit[i] == '7') xuong = 0;
    if (ligit[i] == '1' || ligit[i] == '2' || ligit[i] == '3') len = 0;
    if (ligit[i] == '1' || ligit[i] == '7' || ligit[i] == '4' ||
        ligit[i] == '0')
      trai = 0;
    if (ligit[i] == '3' || ligit[i] == '6' || ligit[i] == '9' ||
        ligit[i] == '0')
      phai = 0;
  }
  if (len == 0 && xuong == 0 && trai == 0 && phai == 0)
    cout << "YES";
  else
    cout << "NO";
}
