#include <bits/stdc++.h>
using namespace std;
int n, key[15];
char s[15];
char str[15];
bool judgeup() {
  for (int i = 0; i < n; ++i) {
    if (key[i] - 3 <= 0) return false;
  }
  return true;
}
bool judgedown() {
  for (int i = 0; i < n; ++i) {
    if (key[i] + 3 > 9 && (key[i] + 3) != 11) return false;
  }
  return true;
}
bool judgeright() {
  for (int i = 0; i < n; ++i) {
    if (key[i] == 11 || key[i] == 3 || key[i] == 6 || key[i] == 9) return false;
  }
  return true;
}
bool judgeleft() {
  for (int i = 0; i < n; ++i) {
    if (key[i] == 11 || key[i] == 1 || key[i] == 4 || key[i] == 7) return false;
  }
  return true;
}
int main() {
  scanf("%d", &n);
  scanf("%s", str);
  for (int i = 0; i < n; ++i) {
    key[i] = str[i] - '0';
    if (key[i] == 0) key[i] = 11;
  }
  if (judgeup() || judgedown() || judgeright() || judgeleft()) {
    printf("NO\n");
  } else {
    printf("YES\n");
  }
  return 0;
}
