#include <bits/stdc++.h>
using namespace std;
const int N = 60;
bool vis[N][N][N][N];
int n, cum[N][N], mem[N][N][N][N];
char A[N][N], a[N][N];
int dp(int x1, int y1, int x2, int y2) {
  if (x1 > x2 || y1 > y2) return 1e9;
  if (cum[x2][y2] - cum[x1 - 1][y2] - cum[x2][y1 - 1] + cum[x1 - 1][y1 - 1] ==
      0)
    return 0;
  int &ret = mem[x1][y1][x2][y2];
  if (vis[x1][y1][x2][y2]) return ret;
  vis[x1][y1][x2][y2] = 1;
  ret = max(x2 - x1 + 1, y2 - y1 + 1);
  for (int i = x1; i < x2; i++)
    ret = min(ret, dp(x1, y1, i, y2) + dp(i + 1, y1, x2, y2));
  for (int i = y1; i < y2; i++)
    ret = min(ret, dp(x1, y1, x2, i) + dp(x1, i + 1, x2, y2));
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%s", &A[i]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) a[i][j] = A[i - 1][j - 1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      cum[i][j] =
          (a[i][j] == '#') + cum[i - 1][j] + cum[i][j - 1] - cum[i - 1][j - 1];
  printf("%d", dp(1, 1, n, n));
}
