#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <unordered_map>
#include <fstream>
#define rep(i,a,n)  for(int i=a;i<=n;i++)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a>b?b:a)
#define pb push_back
typedef long long ll;
using namespace std;
const int mod=1e9+7;
const ll N=100005;
const double esp=1e-6;
void debug(ll x)  { cout<<111<<" "<<x<<'\n'; }
ll n,m,k,tt;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }
int main() {
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  //ifstream s("photo.in");
  //ofstream c("photo.out");
  //freopen("photo.in", "r", stdin);
  //freopen("photo.out", "w", stdout);
  tt=1;
  //cin>>tt;
  while(tt--) {
    cin>>n;
    string s;
    cin>>s;
    if(s[0]!=s[n-1]) cout<<1<<'\n';
    else {
      int f=0;
      for(int i=1;i<=n-3;i++) if(s[i]!=s[0]&&s[i+1]!=s[n-1]) f=1;
      if(f) cout<<2<<'\n';
      else cout<<-1<<'\n';
    }
  }
  return 0;
}
/*

*/

#include<bits/stdc++.h>
#define F first
#define S second
#define LL long long
#define MP make_pair
#define PB push_back
#define I insert

const LL mod=1000000007, N=200005;
using namespace std;

LL n, m, i, j, k, l, r, t, ans[N];
LL fix[N], p[N], fox[N];
vector < LL > v[N];

void go ( LL u, LL par = 0 ){
	fix[u] = fix[par] + 1;
	p[u] = par;
	for ( LL i = 0; i < v[u].size(); ++i ){
		if ( v[u][i] == par ) continue;
		go ( v[u][i], u );
	}
}

void jo ( LL u, LL par = 0 ){
	LL bb = 0;
	ans[u] = ++t;
	for ( LL i = 0; i < v[u].size(); ++i ){
		if ( v[u][i] == par ) continue;
		if ( fox[v[u][i]] ){
			bb = v[u][i];
			continue;
		}
		jo(v[u][i], u);
	}
	if ( bb ){
		jo ( bb, u);
	}
	++t;
}

int main(){
	ios_base::sync_with_stdio(false);
	
	cin >> n;
	for ( i = 1; i < n; ++i ){
		cin >> l >> r;
		v[l].PB(r);
		v[r].PB(l);
	}
	
	go ( 1 );	
	l = 1;	
	for ( i = 1; i <= n; ++i ){
		if ( fix[l] < fix[i] ) l = i;
	}
	go ( l );	
	r = 1;	
	for ( i = 1; i <= n; ++i ){
		if ( fix[r] < fix[i] ) r = i;
	}
	
	k = r;
	while ( k != l ){
		fox[k] = 1;
		k = p[k];
	}
	
	t = 0;
	jo(l);
	
	for ( i = 1; i <= n; ++i ) cout << ans[i] << " ";

	return 0;
}
//      IIIIIIIII      OOOOO             A          NN        N    EEEEEEEEEE
//          I         O     O           A A         N N       N    E
//          I        O       O         A   A        N  N      N    E
//          I        O       O        A     A       N   N     N    E
//          I        O       O       AAAAAAAAA      N    N    N    EEEEEEEE
//          I        O       O      A         A     N     N   N    E
//          I        O       O     A           A    N      N  N    E
//          I         O     O     A             A   N       N N    E
//      IIIIIIIII      OOOOO     A               A  N        NN    EEEEEEEEEE ___ KAPANADZE


