#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>   
#include <stdio.h>    
 
using namespace std;
     
#define F first
#define S second
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;                                  
const int N = (int)2e5 + 123;
const ll inf = (ll)3e18 + 1;
                                       
const double pi = acos(-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};                             
const int dy[] = {0, 1, 0, -1, 0};        
 
int n, a[5201][5201];
string s;

inline int sum (int x, int y, int x2, int y2) {
   return a[x2][y2] - a[x][y2 - 1] - a[x2 - 1][y] + a[x - 1][y - 1];
}

inline bool check (int x) {
   for (int i = 1; i <= n / x; i ++)
      for (int j = 1; j <= n / x; j ++) {
         int new_x = (i - 1) * x + 1, new_y = (j - 1) * x + 1;
         int con_x = new_x + x - 1, con_y = new_y + x - 1;
         int cur = sum (new_x, new_y, con_x, con_y);
         //cout << new_x << ' ' << new_y << ' ' << con_x << ' ' << con_y << ' ' << cur << endl;
         if (0 < cur && cur < x * x) return 0;
      }
   return 1;
}

inline void boost () {
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}

inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) {
      cin >> s;
      for (int j = 0; j < sz (s); j ++) {
         int x;
         if (isalpha (s[j])) x = 10 + s[j] - 'A';
         else x = s[j] - '0';        
         for (int k = 3; k >= 0; k --) {
            a[i][(j + 1) * 4 - k] = ((x & (1 << k)) > 0);
         }
      }
   }
   for (int i = 1; i <= n; i ++)
      for (int j = 1; j <= n; j ++)
         a[i][j] += a[i - 1][j] + a[i][j - 1];
   for (int i = n; i >= 1; i --)
      if (n % i == 0 && check (i))
         cout << i, exit (0);
}
                              
main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);             
   boost ();
   int tt = 1;
// cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}                                                               