#include <bits/stdc++.h>
using namespace std;
int ucitaj()
	{
		bool minus=false;
		int rez=0;
		char ch;
		ch=getchar();
		while (true)
		{
			if (ch=='-') break;
			if (ch>='0' or ch<='9')break;
			ch=getchar();
		}
		if (ch=='-') minus=true; else rez=(ch-'0');
		while (true)
		{
			ch=getchar();
			if (ch<'0' or ch>'9') break;
			rez=rez*10+(ch-'0');
		}
		if (minus)
		{
			return -rez;
		}
		else
		{
			return rez;
		}
	}
int main()
{
	char A[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
	char G[1000],ch;
	int n,i,j,p,e,h;
	p=0;
	h=0;
	n=ucitaj();
	for (i=0;i<n;i++)
	{
		G[i]=getchar();
		ch=getchar();
	}
	if (n<=26)
	{
		printf("0");
	}
	else //n=27
	{
		for (i=0;i<n-1;i++)
		{
			for(j=i+1;j<n;j++)
			{
				if (G[i]==G[j])
				{
					p++;
					G[j]='1';
					if (i+1==j)
					{
						h=1;
					}
					
				}
			}
		}
		e=0;
		if (p==1)
		{
			for (i=0;i<26;i++)
			{
				gor:
					if (e>1) 
					{
						printf("0");
						goto dol;
					}
				if (A[i]!=G[i+e])
				{
					if(G[i+e]=='1')
					{
						e++;
						goto gor;
					}
				}
			}
			if (h==1)
			{
				printf("2");
			}
			else
			{
				printf("1");
			}
		}
		else 
		{
			printf("0");
		}
	}
	dol:
		e=1;
}