#include <bits/stdc++.h>
using namespace std;
string s;
const int maxn = 10;
int a[maxn];
int main() {
  int n;
  cin >> n;
  cin >> s;
  for (int i = 0; i < s.size(); i++) a[s[i] - '0']++;
  if ((a[0] || a[9] || a[7]) && (a[1] || a[4] || a[7]) &&
      (a[1] || a[2] || a[3]) && (a[3] || a[6] || a[9]))
    cout << "YES";
  else if (a[0] && (a[1] || a[2] || a[3]))
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
