#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	string s,x;
	int n;
	bool is_t_win[200010][7] = {};
	cin >> n >> s >> x;
	is_t_win[n][0] = true;
	for(int i = 1;i < 7;i++) is_t_win[n][i] = false;
	int amari = 1;
	for(int i = n - 1;i >= 0;i--){
		for(int j = 0;j < 7;j++){
			if(x[i] == 'T'){
				is_t_win[i][j] = (is_t_win[i + 1][j] || is_t_win[i + 1][(j + (s[i] - '0') * amari) % 7]);
			}else{
				is_t_win[i][j] = (is_t_win[i + 1][j] && is_t_win[i + 1][(j + (s[i] - '0') * amari) % 7]);
			}
		}
		amari = amari * 10 % 7;
	}
	if(is_t_win[0][0]) cout << "Takahashi" << endl;
	else cout << "Aoki" << endl;
}
#include<bits/stdc++.h>
#define re register
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,m,t,nxt[500002],pos,Nxt;
char a[500002],b[500002];
long long ans;
int main(){
	n=read();
	scanf("%s%s",a+1,b+1);
	for(re int i=n;i;--i){
		nxt[i]=pos;
		if(a[i]=='1')pos=i;
	}
	Nxt=nxt[1];
	for(re int i=2;i<=n;++i){
		if(a[i-1]^b[i-1]){
			re int pos=Nxt;
			if(!pos)return puts("-1"),0;
			ans+=pos-(i-1);
			a[pos]='0';
			Nxt=nxt[Nxt];
		}
		if(i==Nxt)Nxt=nxt[Nxt];
	}
	if(a[n]!=b[n])return puts("-1"),0;
	printf("%lld",ans);
}
