#include <bits/stdc++.h>
using namespace std;
char c;
bool bottomcorner;
int n, x, mnx = 4, mxx = -1, mny = 5, mxy = -1;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf(" %c", &c);
    if (c == '0') {
      mxy = 3;
      mny = min(mny, 3);
      mnx = min(mnx, 1);
      mxx = max(mxx, 1);
      continue;
    }
    if (c == '9' || c == '7') bottomcorner = true;
    x = c - '0' - 1;
    mnx = min(mnx, x % 3);
    mxx = max(mxx, x % 3);
    mny = min(mny, x / 3);
    mxy = max(mxy, x / 3);
  }
  if (mxy - mny == 3 ||
      (mxy == 2 && mny == 0 && mxx == 2 && mnx == 0 && bottomcorner))
    printf("YES\n");
  else
    printf("NO\n");
}
