#include <bits/stdc++.h>
using namespace std;
int x[1000] = {4, 1, 1, 1, 2, 2, 2, 3, 3, 3};
int y[1000] = {2, 1, 2, 3, 1, 2, 3, 1, 2, 3};
int X[1005], Y[1005];
int main(int argc, char** argv) {
  int n;
  string a;
  cin >> n >> a;
  int mnx = 1e9, mny = 1e9, mxx = 0, mxy = 0;
  for (int i = 1; i < a.size(); i++) {
    X[i] = x[a[i] - '0'] - x[a[i - 1] - '0'];
    Y[i] = y[a[i] - '0'] - y[a[i - 1] - '0'];
  }
  int cnt = 0;
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= 3; j++) {
      if (i == 4 && j != 2) continue;
      ++cnt;
      int nowx = i, nowy = j;
      for (int k = 1; k < a.size(); k++) {
        nowx += X[k], nowy += Y[k];
        if (nowx <= 3 && nowy <= 3 && nowx >= 1 && nowy >= 1 ||
            (nowx == 4 && nowy == 2)) {
        } else {
          --cnt;
          break;
        }
      }
    }
  }
  if (cnt > 1)
    puts("NO");
  else
    puts("YES");
  return 0;
}
