#include <bits/stdc++.h>
using namespace std;
const int N = 50 + 10;
const int inf = 0x3f3f3f3f;
char s[N][N];
int dp[N][N][N][N];
int dfs(int x1, int y1, int x2, int y2) {
  if (x2 < x1 || y2 < y1) return 0;
  if (dp[x1][y1][x2][y2] != -1) return dp[x1][y1][x2][y2];
  int ok = 0;
  for (int i = x1; i <= x2; i++)
    for (int j = y1; j <= y2; j++)
      if (s[i][j] == '#') ok++;
  if (!ok) return dp[x1][y1][x2][y2] = 0;
  if (x2 == x1 && y1 == y2) return dp[x1][y1][x2][y2] = 1;
  int res = inf;
  for (int i = x1; i < x2; i++) {
    int tep = dfs(x1, y1, i, y2) + dfs(i + 1, y1, x2, y2);
    res = min(res, tep);
  }
  for (int j = y1; j < y2; j++) {
    int tep = dfs(x1, y1, x2, j) + dfs(x1, j + 1, x2, y2);
    res = min(res, tep);
  }
  int len = max(x2 - x1, y2 - y1) + 1;
  return dp[x1][y1][x2][y2] = min(len, res);
}
int main() {
  memset(dp, -1, sizeof dp);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  printf("%d\n", dfs(0, 0, n - 1, n - 1));
}
