#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string x;
  bool up = true, down = true, left = true, right = true;
  cin >> n;
  cin >> x;
  for (int i = 0; i < n; ++i) {
    if (x[i] == '0') {
      down = false;
      left = false;
      right = false;
    }
    if (x[i] == '1' || x[i] == '4' || x[i] == '7') {
      left = false;
      if (x[i] == '1') {
        up = false;
      }
      if (x[i] == '7') {
        down = false;
      }
    }
    if (x[i] == '3' || x[i] == '6' || x[i] == '9') {
      right = false;
      if (x[i] == '3') {
        up = false;
      }
      if (x[i] == '9') {
        down = false;
      }
    }
    if (x[i] == '2') {
      up = false;
    }
  }
  if (!up && !down && !left && !right) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  return 0;
}
