/***In The Name Of God**/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool mark[11];
bool flag1,flag2;
int main()
{
ll n;
string s;
cin>>n;
cin>>s;
for(int 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[3]||mark[6]||mark[9]))
flag2=true;
if((mark[1]||mark[2]||mark[3])&&mark[0]){
cout<<"YES";
return 0;
}
if(flag1&&flag2){
cout<<"YES";
return 0;
}
cout<<"NO";
return 0;
}
LyoqKkluIFRoZSBOYW1lIE9mIEdvZCoqLwojaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKCmJvb2wgbWFya1sxMV07CmJvb2wgZmxhZzEsZmxhZzI7CgppbnQgbWFpbigpCnsKICAgIGxsIG47CiAgICBzdHJpbmcgczsKICAgIGNpbj4+bjsKICAgIGNpbj4+czsKICAgIGZvcihpbnQgaT0wO2k8bjtpKyspewogICAgICAgIG1hcmtbc1tpXS0nMCddPXRydWU7CiAgICB9CiAgICBpZigobWFya1sxXXx8bWFya1syXXx8bWFya1szXSkmJihtYXJrWzddfHxtYXJrWzldKSkKICAgICAgICBmbGFnMT10cnVlOwogICAgaWYoKG1hcmtbMV18fG1hcmtbNF18fG1hcmtbN10pJiYobWFya1szXXx8bWFya1s2XXx8bWFya1s5XSkpCiAgICAgICAgZmxhZzI9dHJ1ZTsKICAgIGlmKChtYXJrWzFdfHxtYXJrWzJdfHxtYXJrWzNdKSYmbWFya1swXSl7CiAgICAgICAgY291dDw8IllFUyI7CiAgICAgICAgcmV0dXJuIDA7CiAgICB9CiAgICBpZihmbGFnMSYmZmxhZzIpewogICAgICAgIGNvdXQ8PCJZRVMiOwogICAgICAgIHJldHVybiAwOwogICAgfQogICAgY291dDw8Ik5PIjsKcmV0dXJuIDA7Cn0KCg==