#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
string M;
cin>>N>>M;
string me="QWERTYUIOPASDFGHJKLZXCVBNM";
int jml_hf[26];
memset(jml_hf, 0, sizeof jml_hf);
for(int i=0; i<N; i++){
for(int j=0; j<26;j++){
if(M[i]==me[j]){
jml_hf[j]++;
cout<<jml_hf[j];
}
}
}
sort(jml_hf, jml_hf+26, greater<int>());
int the=0;
if(jml_hf[2]<1){
the=-1;
}
else{
the=jml_hf[2]*3;
if(jml_hf[0]>jml_hf[2]){
the++;
}
if(jml_hf[1]<jml_hf[2]){
the++;
}
}
cout<<the<<endl;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKXsKICAgIGludCBOOwogICAgc3RyaW5nIE07CiAgICBjaW4+Pk4+Pk07CiAgICAKICAgIHN0cmluZyBtZT0iUVdFUlRZVUlPUEFTREZHSEpLTFpYQ1ZCTk0iOwogICAgaW50IGptbF9oZlsyNl07CiAgICBtZW1zZXQoam1sX2hmLCAwLCBzaXplb2Ygam1sX2hmKTsKICAgIGZvcihpbnQgaT0wOyBpPE47IGkrKyl7CiAgICAgICAgZm9yKGludCBqPTA7IGo8MjY7aisrKXsKICAgICAgICAgICAgCiAgICAgICAgICAgIGlmKE1baV09PW1lW2pdKXsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgam1sX2hmW2pdKys7CiAgICAgICAgICAgICAgICBjb3V0PDxqbWxfaGZbal07CiAgICAgICAgICAgIH0KICAgICAgICAgICAKICAgICAgICB9CiAgICAgICAgCiAgICB9CiAgICBzb3J0KGptbF9oZiwgam1sX2hmKzI2LCBncmVhdGVyPGludD4oKSk7CiAgIGludCB0aGU9MDsKICAgaWYoam1sX2hmWzJdPDEpewogICAgICAgdGhlPS0xOwogICB9CiAgIGVsc2V7CiAgICAgICB0aGU9am1sX2hmWzJdKjM7CiAgICAgICBpZihqbWxfaGZbMF0+am1sX2hmWzJdKXsKICAgICAgICAgICB0aGUrKzsKICAgICAgIH0KICAgICAgIGlmKGptbF9oZlsxXTxqbWxfaGZbMl0pewogICAgICAgICAgIHRoZSsrOwogICAgICAgfQogICB9CiAgIGNvdXQ8PHRoZTw8ZW5kbDsKfQo=