#include <bits/stdc++.h>
using namespace std;
const int MX = 510;
int dp[55][55][55][55];
char M[55][55];
int dfs(int a, int b, int x, int y) {
  if (a == x && b == y) return (M[a][b] == '#');
  if (dp[a][b][x][y] != -1) return dp[a][b][x][y];
  dp[a][b][x][y] = max(x - a, y - b) + 1;
  for (int i = a; i <= x - 1; i++)
    dp[a][b][x][y] = min(dp[a][b][x][y], dfs(a, b, i, y) + dfs(i + 1, b, x, y));
  for (int i = b; i <= y - 1; i++)
    dp[a][b][x][y] = min(dp[a][b][x][y], dfs(a, b, x, i) + dfs(a, i + 1, x, y));
  return dp[a][b][x][y];
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> M[i];
  memset(dp, -1, sizeof(dp));
  cout << dfs(0, 0, n - 1, n - 1) << '\n';
  return 0;
}
