#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> v;
void solve(){
int k; cin>>k;
string str; cin>>str;
int n = str.size();
int kk = k;
int insize = n;
vector<int> state;
while(kk > 1){
state.push_back(insize);
insize/=2;
kk--;
}
//cout<<insize<<"\n";
if(insize == 0 || insize == 2 || insize == 3){
cout<<"impossible"<<"\n";
}
else{
state.push_back(insize);
insize/=2;
int mega = insize;
for(int i = 0; i<insize; i++){
v.push_back({i});
}
//reverse(state.begin(), state.end());
while(state.size() != 0){
int x = state[state.size()-1];
//cout<<insize<<" ";
//cout<<x<<" ";
x-=2*insize ;
int asolsize = 2*insize + x;
for(int i = 0; i<v.size(); i++){
vector<int> temp;
for(auto z: v[i]){
temp.push_back(asolsize - z-1);
}
for(auto z: temp){
v[i].push_back(z);
}
}
if(x == 1) v.push_back({insize});
insize = asolsize;
state.pop_back();
//cout<<insize<<"\n";
}
// for(int i = 0; i<v.size(); i++){
// for(auto x: v[i]){
// cout<<x<<" ";
// }
// cout<<"\n";
// }
vector<pair<int, int>> L;
vector<pair<int, int>> R;
int cng = 0;
for(int i = 0; i<v.size(); i++){
vector<int> hsh(26, 0);
for(auto x: v[i]){
hsh[str[x]-'a']++;
}
vector<pair<int, int>> pp;
for(int i = 0; i<26; i++){
pp.push_back({hsh[i], i});
}
sort(pp.begin(), pp.end());
reverse(pp.begin(), pp.end());
// for(int i = 0; i<3; i++) cout<<hsh[i]<<" ";
// cout<<"\n";
L.push_back({pp[0].second, pp[1].second});
R.push_back({v[i].size() - pp[0].first, v[i].size() - pp[1].first});
cng+= v[i].size() - pp[0].first;
}
bool flag = 0;
insize = mega;
//cout<<mega<<"\n";
for(int i = 0; i<insize; i++){
if(L[i].first != L[insize - i-1].first) flag = 1;
}
if(flag){
cout<<cng<<"\n";
}
else{
int ans = 1e9;
if(insize == 0) ans = cng;
for(int i = 0; i<insize/2; i++){
ans = min(ans, cng - R[i].first + R[i].second);
}
for(int i = (insize+1)/2; i<insize; i++){
ans = min(ans, cng - R[i].first + R[i].second);
}
cout<<ans<<"\n";
}
}
}
signed main(){
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
// cout.tie(NULL);
int t=1; //cin>>t;
//cout<<t<<"\n";
while(t--) solve();
return 0;
}