#include <bits/stdc++.h>
using namespace std;
int n;
char A[55][55];
int dp[55][55][55][55];
int dfs(int x1, int y1, int x2, int y2) {
  if (~dp[x1][y1][x2][y2]) return dp[x1][y1][x2][y2];
  if (x1 == x2 && y1 == y2) return (A[x1][y1] == '#');
  int res = max(x2 - x1 + 1, y2 - y1 + 1);
  for (int i = x1; i < x2; i++)
    res = min(res, dfs(x1, y1, i, y2) + dfs(i + 1, y1, x2, y2));
  for (int i = y1; i < y2; i++)
    res = min(res, dfs(x1, y1, x2, i) + dfs(x1, i + 1, x2, y2));
  return dp[x1][y1][x2][y2] = res;
}
int main() {
  scanf("%d", &n);
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) scanf("%s", A[i] + 1);
  printf("%d\n", dfs(1, 1, n, n));
  return 0;
}
