#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 15;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') ans &= 8;
    if (s[i] == '1' || s[i] == '2' || s[i] == '3') ans &= 7;
    if (s[i] == '1' || s[i] == '4' || s[i] == '7') ans &= 13;
    if (s[i] == '3' || s[i] == '6' || s[i] == '9') ans &= 14;
    if (s[i] == '7' || s[i] == '9') ans &= 11;
  }
  if (ans)
    cout << "NO";
  else
    cout << "YES";
  return 0;
}
