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