#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)
//__builtin_popcountll()


int main(){

    fast;
    int n,i,j;
    cin>>n;
    int a[n+1];
    for(i=1;i<=n;i++)
    cin>>a[i];
    set<int>s;
    for(i=1;i<n;i++)
    s.insert(i);
    vector<int>ans;
    for(i=1;i<=n;i++)
    {
    	if(a[i]==i)
    	{
    		cout<<-1;
    		return 0;
		}
    	if(a[i]>i)
    	continue;
    	else
    	{
    		for(j=i-1;j>=a[i];j--)
    		{
    			if(s.find(j)==s.end())
    			{
    				cout<<-1;
    				return 0;
				}
				else
				{
					s.erase(j);
					ans.pb(j);
				}
			}
		}
	}
	if(s.size()==0)
	{
		for(i=0;i<ans.size();i++)
		cout<<ans[i]<<" ";
	}
	else
	{
		cout<<-1;
	}
    
}
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, init, end) for(ll i = init; i < end; i++)
#define REP(i, init, end) for(ll i = init; i < end + 1; i++)
#define rev(i, end, init) for(ll i = init - 1; i >= end; i--)
#define REV(i, end, init) for(ll i = init; i >= end; i--)
#define PI 3.14159265359
// #define EPS 0.0000000001
// #define MOD 1000000007
#define INF 100000000000000000
// #define MAX 100000000000
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll N;
    cin >> N;

    string S, X;
    cin >> S >> X;

    ll dp[N][7]; // 0: Takahashi wins, 1: Aoki wins
    rep(i, 0, N){
        rep(j, 0, 7){
            dp[i][j] = -1;
        }
    }

    rep(j, 0, 7){
        if(X[N - 1] == 'A'){
            if(j == 0 && (S[N - 1] == '0' || S[N - 1] == '7')){
                dp[N - 1][j] = 0;
            }else{
                dp[N - 1][j] = 1;
            }
        }else{
            if(j == 0){
                dp[N - 1][j] = 0;
            }else{
                if(((j * 10) + (S[N - 1] - '0')) % 7 == 0){
                    dp[N - 1][j] = 0;
                }else{
                    dp[N - 1][j] = 1;
                }
            }
        }
    }

    rev(i, 0, N - 1){
        rep(j, 0, 7){
            if(X[i] == 'A'){
                dp[i][j] = max(dp[i + 1][(j * 10) % 7], dp[i + 1][((j * 10) + (S[i] - '0')) % 7]);
            }else{
                dp[i][j] = min(dp[i + 1][(j * 10) % 7], dp[i + 1][((j * 10) + (S[i] - '0')) % 7]);
            }
        }
    }

    if(dp[0][0] == 0){
        cout << "Takahashi" << endl;
    }else{
        cout << "Aoki" << endl;
    }

    return 0;
}

