#include <bits/stdc++.h>
using namespace std;
bool mark[11];
bool flag1, flag2;
long long solve() {
  long long n, i;
  string s;
  cin >> n >> s;
  for (i = 0; i < n; i++) {
    mark[s[i] - '0'] = true;
  }
  if ((mark[1] || mark[2] || mark[3]) && (mark[7] || mark[9])) {
    flag1 = true;
  }
  if ((mark[1] || mark[4] || mark[7]) && (mark[9] || mark[6] || mark[3])) {
    flag2 = true;
  }
  if ((mark[1] || mark[2] || mark[3]) && mark[0]) {
    cout << "YES" << '\n';
    return 0;
  }
  if (flag1 && flag2) {
    cout << "YES" << '\n';
  } else {
    cout << "NO" << '\n';
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
