//#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define CT printf("\n-------------------------\n");
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll Inf=1ll<<60ll;
typedef pair<int,int> pii;
const int N=100005;
priority_queue<pii,vector<pii>,greater<pii> > q[26];
int n,dp[N];
char s[N];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);

	scanf("%d",&n);
	scanf("%s",s+1);
	memset(dp,0x3f,sizeof(dp));
	dp[0]=0;
	for(int i=0;i<=n;++i){
		for(int j=0;j<26;++j){
			if(q[j].empty()||j==s[i]-'a')continue;
			pii tmp=q[j].top();
			dp[i]=min(dp[i],dp[tmp.second]+1);
		}
		if(i==n)break;
		q[s[i+1]-'a'].push(make_pair(dp[i],i));
	}
	if(dp[n]==inf){puts("-1");return 0;}
	printf("%d\n",dp[n]);

//	fclose(stdin);fclose(stdout);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
using tp = tuple<ll, ll, ll>;

constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll) 1e9 + 7;
constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;

using Array = vector<ll>;
using Matrix = vector<Array>;

/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

void solve() {
    int n;
    cin >> n;
    vec<ll> a(n);
    REP(i, n) cin >> a[i];

    vec<ll> used(n, 0);
    set<int> b;
    REP(i, n - 1) {
        if (a[i] > i + 1 and a[i + 1] < i + 2) {
            used[i] = 1;
            b.insert(i);
        }
    }

    vec<int> ans;
    while (b.size()) {
        auto it = b.begin();
        b.erase(it);
        int i = *it;
        //cout<<i+1<<en;
        used[i] = -1;
        ans.push_back(i + 1);
        swap(a[i], a[i + 1]);
        if (i - 1 >= 0) {
            if (used[i - 1] != -1) {
                if (a[i - 1] > i and a[i] < i + 1) {
                    used[i-1] = 1;
                    b.insert(i - 1);
                } else {
                    used[i-1] = 0;
                    b.erase(i - 1);
                }
            }
        }

        if (i + 2 < n) {
            if (used[i + 1] != -1) {
                if (a[i + 1] > i+2 and a[i + 2] < i + 3) {
                    used[i+1] = 1;
                    b.insert(i + 1);
                } else {
                    used[i+1] = 0;
                    b.erase(i + 1);
                }
            }
        }
    }

    if (ans.size() != n-1) {
        cout << -1 << en;
        return;
    }
    REP(i, n) {
        if (a[i] != i + 1) {
            cout << -1 << en;
            return;
        }
    }
    for (auto i:ans) cout << i << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
/*
    ll t;
    cin >> t;
    REP(i, t - 1) {
        solve();
    }*/

    solve();

    return 0;
}
