import java.util.*;
import java.io.*;

public class P1107D {

  private static String[] hex = {
    "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101",
      "1110", "1111"
  };

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

  private static void solve() {
    int n = nextInt();

    Set<Integer> factors = new HashSet<>();
    for (int i = 1; i <= n; i++) {
      if (n % i == 0) {
        factors.add(i);
      }
    }

    char[][] g = new char[n][n];

    for (int i = 0; i < n; i++) {
      char[] x = next().toCharArray();
      int l = 0;
      for (int j = 0; j < x.length; j++) {
        int index = x[j] - '0';
        if (x[j] >= 'A' && x[j] <= 'F') {
          index = x[j] - 'A';
        }

        char[] tmp = hex[index].toCharArray();
        for (int k = 0; k < 4; k++) {
          g[i][l++] = tmp[k];
        }
      }
    }

    int[][] rs = new int[n][n];
    for (int i = 0; i < n; i++) {
      rs[i][0] = g[i][0] - '0';
      for (int j = 1; j < n; j++) {
        rs[i][j] = rs[i][j - 1] + (g[i][j] - '0');
      }
    }

    int[][] cs = new int[n][n];
    for (int i = 0; i < n; i++) {
      cs[0][i] = g[0][i] - '0';
      for (int j = 1; j < n; j++) {
        cs[j][i] = cs[j - 1][i] + (g[j][i] - '0');
      }
    }

    int ans = 1;
    for (Integer f : factors) {
      boolean good = true;
      for (int i = 0; i < n && good; i++) {
        for (int j = f; j < n && good; j += f) {
          int diff = rs[i][j] - (j == f ? 0 : rs[i][j - f - 1]);
          if (diff != 0 && diff != f) {
            good = false;
          }
        }
      }

      for (int i = 0; i < n && good; i++) {
        for (int j = f; j < n && good; j += f) {
          int diff = cs[j][i] - (j == f ? 0 : cs[j - f - 1][i]);
          if (diff != 0 && diff != f) {
            good = false;
          }
        }
      }

      if (f == n) {
        int t = g[0][0];
        for (int i = 0; i < n && good; i++) {
          for (int j = 0; j < n && good; j++) {
            if (t != g[i][j]) {
              good = false;
            }
          }
        }
      }

      if (good) {
        ans = Math.max(ans, f);
      }
    }

    System.out.println(ans);

  }

  private static void dfs(int i, int j, char c, boolean[][] vis, char[][] g, int n, Map<Integer, Integer> map) {
    vis[i][j] = true;
    map.put(i, Math.max(map.getOrDefault(i, -1), j));

    for (int k = 0; k < dx.length; k++) {
      int nx = i + dx[k];
      int ny = j + dy[k];

      if (nx >= 0 && nx < n && ny >= 0 && ny < n && !vis[nx][ny] && g[nx][ny] == c)  {
        dfs(nx, ny, c, vis, g, n, map);
      }
    }
  }

  private static void run() {
    br = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out);

    solve();

    out.close();
  }

  private static StringTokenizer st;
  private static BufferedReader br;
  private static PrintWriter out;

  private static String next() {
    while (st == null || !st.hasMoreElements()) {
      String s;
      try {
        s = br.readLine();
      } catch (IOException e) {
        return null;
      }
      st = new StringTokenizer(s);
    }
    return st.nextToken();
  }

  private static int nextInt() {
    return Integer.parseInt(next());
  }

  private static long nextLong() {
    return Long.parseLong(next());
  }

  public static void main(String[] args) {
    run();
  }
}