#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, c = 0;
  string x;
  cin >> n >> x;
  pair<int, int> ans[9];
  int a[10] = {3, 0, 0, 0, 1, 1, 1, 2, 2, 2};
  int b[10] = {1, 0, 1, 2, 0, 1, 2, 0, 1, 2};
  for (int i = 1; i < n; i++) {
    ans[i].first = a[x[i] - '0'] - a[x[i - 1] - '0'];
    ans[i].second = b[x[i] - '0'] - b[x[i - 1] - '0'];
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      bool k = 0;
      int X = i, Y = j;
      for (int I = 1; I < n; I++) {
        if (X == 3 && Y != 1) {
          k = 1;
          break;
        }
        X = X + ans[I].first;
        Y = Y + ans[I].second;
        if (X < 0 || X >= 4 || Y < 0 || Y >= 3 || (X == 3 && Y != 1)) {
          k = 1;
          break;
        }
      }
      if (!k) c++;
    }
  }
  cout << (c > 1 ? "NO\n" : "YES\n");
}
