#include<stdio.h>
int main()
{
int i,j,n,t = 1,l = 0,cnt = 0,ret = 7;
scanf("%d",&n);
getchar();
getchar();
char first[n][n];
char last[n][n];
char first1[n][n];
for(i = 0;i < n;i++){
for (j = 0;j < n;j++){
scanf("%1s",&first[i][j]);
}
getchar();
getchar();
}
for(i = 0;i < n;i++){
for(j = 0;j < n;j++){
scanf("%1s",&last[i][j]);
}
getchar();
getchar();
}
for(i = 0;i < n&&t==1;i++){
for(j = 0;j < n&&t==1;j++){
l = 6;
if(first[i][j] != last[i][j]){
l = 0;
t = 0;
}
}
}
if(l == 6)
ret = 6;
t = 1;
for(i = 0;i < n;i++){
for(j = 0;j < n;j++){
first1[i][n-1-j] = first[i][j];
}
}
for(i = 0;i < n&&t==1;i++){
for(j = 0;j < n&&t==1;j++){
l = 5;
if(first1[i][j] != last[j][n-1-i]){
l = 0;
t = 0;
}
}
}
if(l == 5)
ret = 5;
t = 1;
for(i = 0;i < n&&t==1;i++){
for(j = 0;j < n&&t==1;j++){
l = 5;
if(first1[i][j] != last[n-1-i][n-1-j]){
l = 0;
t = 0;
}
}
}
if(l == 5)
ret = 5;
t = 1;
for(i = 0;i < n&&t==1;i++){
for(j = 0;j < n&&t==1;j++){
l = 5;
if(first1[i][j] != last[n-j-1][i]){
l = 0;
t = 0;
}
}
}
if(l == 5)
ret = 5;
t = 1;
for(i = 0;i < n&&t==1;i++){
for(j = 0;j < n&&t==1;j++){
l = 4;
if(first[i][j] != last[i][n-1-j]){
l = 0;
t = 0;
}
}
}
if(l == 4)
ret = 4;
t = 1;
for(i = 0;i < n&&t==1;i++){
for(j = 0;j < n&&t==1;j++){
l = 3;
if(first[i][j] != last[n-j-1][i]){
l = 0;
t = 0;
}
}
}
if(l == 3)
ret = 3;
t = 1;
for(i = 0;i < n&&t==1;i++){
for(j = 0;j < n&&t==1;j++){
l = 2;
if(first[i][j] != last[n-1-i][n-1-j]){
l = 0;
t = 0;
}
}
}
if(l == 2)
ret = 2;
t = 1;
for(i = 0;i < n&&t==1;i++){
for(j = 0;j < n&&t==1;j++){
l = 1;
if(first[i][j] != last[j][n-1-i]){
l = 0;
t = 0;
}
}
}
if(l == 1)
ret = 1;
printf("%d",ret);
return 0;
}