#include<bits/stdc++.h>
using namespace std;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,a,b) for(i=(a);i<=(b);++i)
#define per(i,a,b) for(i=(a);i>=(b);--i)
#define REP(i,a,b) for(i=(a);i< (b);++i)
#define PER(i,a,b) for(i=(a);i> (b);--i)
#define ERR(...) fprintf(stderr,__VA_ARGS__)
template<class T>inline void cmn(T &x,const T &a){if(a<x)x=a;}
template<class T>inline void cmx(T &x,const T &a){if(x<a)x=a;}
template<class T>inline bool bmn(T &x,const T &a){if(a<x){x=a;return true;}else return false;}
template<class T>inline bool bmx(T &x,const T &a){if(x<a){x=a;return true;}else return false;}

const int MAXN=100005;
char S[MAXN];
signed main(){
#ifdef ONLINE_JUDGE
	//freopen("problemname.in","r",stdin);
	//freopen("problemname.out","w",stdout);
#endif
	int N;
	scanf("%d%s",&N,S);
	if(S[0]!=S[N-1])puts("1");
	else{
		int i;
		REP(i,1,N-2)if(S[i]!=S[0]&&S[0]!=S[i+1]){
			puts("2");
			return 0;
		}
		puts("-1");
	}
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int cnt[N];
int main() {
	string s;
	cin>>s;
	int f=0; 
	int g=0;
	int x=0;
	if(s.size()==1) {
		if(s[0]=='8') {
			cout<<"Yes"<<endl;
			return 0;
		}
		else {
			cout<<"No"<<endl;
			return 0;	
		}
	}
	else if(s.size()==2) {
		int cur = s[0]-'0';
		int cur1= s[1]-'0';
		if((cur*10+cur1)%8==0 || (cur1*10+cur)%8==0) {
			cout<<"Yes"<<endl;
			return 0;	
		}
		else {
			cout<<"No"<<endl;
			return 0;	
		}
	}
	string op = s;
	
for(int i = 0; i < op.size(); i++)//判断字符串有多少数字 
    {
    	char tmp = op[i];
    	cnt[op[i] - '0']++;
	}
	int time = 100 / 8 + 1;
	int flg = 1;
	for(int i = time; 8 * i < 1000; i++)//枚举100-1000里8的倍数 
	{
		flg = 1;
		int tmp = 8 * i;
		int tmpp[10] = {0};//8的倍数的数字组成 
		while(tmp)
		{
			if(tmp%10 == 0)
			{
				flg = 0;
				break;
			}
			tmpp[tmp%10]++;
			tmp /= 10;
		}
		if(flg == 0) continue;
		for(int i = 1; i < 10; i++)
		{
			if(cnt[i] < tmpp[i])
			{
				flg = 0;
				break;
			}
		}
		if(flg)
		{
			break;
		}
		
	}
	if(flg)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
    return 0;
}