#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma G++ optimize(2)
using namespace std;
const int MAX_N = 55;
char g[MAX_N][MAX_N];
int n, sum[MAX_N][MAX_N];
int dp[MAX_N][MAX_N][MAX_N][MAX_N];
int dfs(int x1, int y1, int x2, int y2) {
  if (~dp[x1][y1][x2][y2]) return dp[x1][y1][x2][y2];
  if (sum[x2][y2] - sum[x2][y1 - 1] - sum[x1 - 1][y2] + sum[x1 - 1][y1 - 1] ==
      0)
    return dp[x1][y1][x2][y2] = 0;
  int ans = max(x2 - x1 + 1, y2 - y1 + 1);
  for (register int i = x1; i <= x2 - 1; ++i)
    ans = min(ans, dfs(x1, y1, i, y2) + dfs(i + 1, y1, x2, y2));
  for (register int i = y1; i <= y2 - 1; ++i)
    ans = min(ans, dfs(x1, y1, x2, i) + dfs(x1, i + 1, x2, y2));
  return dp[x1][y1][x2][y2] = ans;
}
int main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; ++i) scanf("%s", g[i] + 1);
  for (register int i = 1; i <= n; ++i)
    for (register int j = 1; j <= n; ++j)
      sum[i][j] = (g[i][j] == '#'),
      sum[i][j] += (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1]);
  memset(dp, -1, sizeof(dp));
  printf("%d\n", dfs(1, 1, n, n));
  return 0;
}
