/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class x1107D
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int[][] grid = new int[N][N];
         for(int i=0; i < N; i++)
         {
            String input = infile.readLine();
            int dex = 0;
            for(int a=0; a < N/4; a++)
            {
               int lol = Integer.parseInt(input.substring(a,a+1),16);
               for(int b=3; b >= 0; b--)
               {
                  if((lol&(1<<b))>0)
                     grid[i][dex] = 1;
                  dex++;
               }
            }
         }
         int[][] dp = new int[N][N];
         dp[0][0] = grid[0][0];
         for(int i=1; i < N; i++)
         {
            dp[i][0] += grid[i][0]+grid[i-1][0];
            dp[0][i] += grid[0][i]+grid[0][i-1];
         }
         for(int i=1; i < N; i++)
            for(int j=1; j < N; j++)
               dp[i][j] = grid[i][j]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
         ArrayList<Integer> divs = findDiv(N);
         int res = 1;
         for(int d: divs)
         {
            if(d == 1)
               continue;
            boolean pos = true;
            for(int i=d-1; i < N; i+=d)
               for(int j=d-1; j < N; j+=d)
               {
                  int sum = query(i-d+1,j-d+1,i,j,dp);
                  if(sum > 0 && sum < d*d)
                     pos = false;
               }
            if(pos)
               res = Math.max(res, d);
         }
         System.out.println(res);
      }
      public static int query(int a, int b, int c, int d, int[][] dp)
      {
         int val = dp[c][d];
         if(a == 0 && b == 0)
            return val;
         else if(a == 0)
            return val-dp[c][b-1];
         else if(b == 0)
            return val-dp[a-1][d];
         return dp[c][d]-dp[c][b-1]-dp[a-1][d]+dp[a-1][b-1];
      }
      public static ArrayList<Integer> findDiv(int N)
      {
         //gens all divisors of N
         ArrayList<Integer> ls1 = new ArrayList<Integer>();
         ArrayList<Integer> ls2 = new ArrayList<Integer>();
         for(int i=1; i <= (int)(Math.sqrt(N)+0.00000001); i++)
            if(N%i == 0)
            {
               ls1.add(i);
               ls2.add(N/i);
            }
         Collections.reverse(ls2);
         for(int b: ls2)
            if(b != ls1.get(ls1.size()-1))
               ls1.add(b);
         return ls1;
      }
   }