#include <bits/stdc++.h>
using namespace std;
int n;
string st;
int checkpos(int x, int y) {
  if (x >= 1 && x <= 3 && y >= 0 && y <= 2) return 1;
  if (x == 0 && y == 1) return 1;
  return 0;
}
int check(int n, int act) {
  int x, y;
  switch (n) {
    case 0:
      x = 0;
      y = 1;
      break;
    case 7:
      x = 1;
      y = 0;
      break;
    case 8:
      x = 1;
      y = 1;
      break;
    case 9:
      x = 1;
      y = 2;
      break;
    case 4:
      x = 2;
      y = 0;
      break;
    case 5:
      x = 2;
      y = 1;
      break;
    case 6:
      x = 2;
      y = 2;
      break;
    case 1:
      x = 3;
      y = 0;
      break;
    case 2:
      x = 3;
      y = 1;
      break;
    case 3:
      x = 3;
      y = 2;
      break;
  }
  switch (act) {
    case 0:
      return checkpos(x - 1, y);
    case 1:
      return checkpos(x, y + 1);
    case 2:
      return checkpos(x + 1, y);
    case 3:
      return checkpos(x, y - 1);
  }
  return 0;
}
int main() {
  cin >> n;
  cin >> st;
  for (int i = 0; i < 4; ++i) {
    bool kt = true;
    for (int j = 0; j < n; ++j) {
      kt = check(st[j] - '0', i);
      if (!kt) break;
    }
    if (kt == true) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
