#include <bits/stdc++.h>
using namespace std;
char juzhen[15][15];
char temp[15][15];
char final[15][15];
int n;
void debug(){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<juzhen[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
return;
}
void copy(){
memset(temp,0,sizeof(temp));
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
temp[i][j]=juzhen[i][j];
}
}
}
bool check(){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(final[i][j]!=juzhen[i][j]){
return 0;
}
}
}
return 1;
}
void rotate90(){
copy();
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
juzhen[j][n-i+1]=temp[i][j];
}
}
copy();
}
void rotate180(){
rotate90();
rotate90();
}
void rotate270(){
rotate90();
rotate90();
rotate90();
}
void shuiping(){
for(int i=1;i<=n/2;i++){
for(int j=1;j<=n;j++){
swap(juzhen[i][j],juzhen[n+1-i][j]);
}
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>juzhen[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>final[i][j];
}
}
if(check()){
cout<<6;
return 0;
}
rotate90();
if(check()){
cout<<1;
return 0;
}
rotate180();
if(check()){
cout<<2;
return 0;
}
rotate270();
if(check()){
cout<<3;
return 0;
}
shuiping();
if(check()){
cout<<4;
return 0;
}
shuiping();
rotate90();
if(check()){
cout<<5;
return 0;
}
shuiping();
rotate180();
if(check()){
cout<<5;
return 0;
}
shuiping();
rotate270();
if(check()){
cout<<5;
return 0;
}
cout<<7;
return 0;
}