#include <bits/stdc++.h>
using namespace std;
long long x(long long s) {
  if (s < 0 || s > 9) return -1;
  if (s == 0) return 1;
  return (s - 1) % 3;
}
long long y(long long s) {
  if (s < 0 || s > 9) return -1;
  if (s == 0) return 3;
  return (s - 1) / 3;
}
long long f(long long x, long long y) {
  if (x == 1 && y == 3) return 0;
  if (x < 0 || y < 0 || x >= 3 || y >= 3) return -1;
  return 1 + x + y * 3;
}
signed main() {
  long long n;
  cin >> n;
  string st;
  cin >> st;
  vector<long long> s(n);
  for (long long i = 0, i_len = n; i < i_len; i++) {
    s[i] = st[i] - '0';
  }
  long long res = 0;
  for (long long i = (-4); i < (4); i++) {
    for (long long j = (-4); j < (4); j++) {
      bool ok = true;
      for (long long ss : s) {
        if (f(x(ss) + i, y(ss) + j) == -1) {
          ok = false;
          break;
        }
      }
      if (ok) {
        res++;
      }
    }
  }
  if (res == 1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
