#include <bits/stdc++.h>
using namespace std;
int a[10];
map<int, pair<int, int>> mp;
vector<int> x;
vector<int> y;
bool check(int b, int c) {
  for (int i = 0; i < x.size(); i++) {
    b += x[i];
    c += y[i];
    if (b < 1 || b > 4) return 0;
    if (c < 1 || c > 3) return 0;
    if (b == 4 && c != 2) return 0;
  }
  return 1;
}
int main() {
  mp[1] = make_pair(1, 1);
  mp[2] = make_pair(1, 2);
  mp[3] = make_pair(1, 3);
  mp[4] = make_pair(2, 1);
  mp[5] = make_pair(2, 2);
  mp[6] = make_pair(2, 3);
  mp[7] = make_pair(3, 1);
  mp[8] = make_pair(3, 2);
  mp[9] = make_pair(3, 3);
  mp[0] = make_pair(4, 2);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%1d", &a[i]);
  for (int i = 1; i < n; i++) {
    x.push_back(mp[a[i]].first - mp[a[i - 1]].first);
    y.push_back(mp[a[i]].second - mp[a[i - 1]].second);
  }
  bool ans = 1;
  for (int i = 0; i <= 9; i++) {
    if (i != a[0]) {
      int b = mp[i].first;
      int c = mp[i].second;
      if (check(b, c)) ans = 0;
    }
  }
  if (ans)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
