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