#include <bits/stdc++.h>
using namespace std;
string G[55];
int dp[55][55][55][55];
bool vis[55][55][55][55];
int Solve(int x1, int y1, int x2, int y2) {
  if (x1 > x2 || y1 > y2) return 0;
  if (x1 == x2 && y1 == y2) return G[x1 - 1][y1 - 1] == '#';
  if (vis[x1][y1][x2][y2]) return dp[x1][y1][x2][y2];
  vis[x1][y1][x2][y2] = true;
  int ret = max(x2 - x1 + 1, y2 - y1 + 1);
  for (int row = y1; row < y2; row++)
    ret = min(ret, Solve(x1, y1, x2, row) + Solve(x1, row + 1, x2, y2));
  for (int col = x1; col < x2; col++)
    ret = min(ret, Solve(x1, y1, col, y2) + Solve(col + 1, y1, x2, y2));
  return dp[x1][y1][x2][y2] = ret;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) cin >> G[i];
  printf("%d", Solve(1, 1, n, n));
}
