#include <bits/stdc++.h>
using namespace std;
string grid[51];
int onesum[51][51];
int dp[51][51][51][51];
bool hasones(int x1, int y1, int x2, int y2) {
  return (onesum[x2][y2] - onesum[x1 - 1][y2] - onesum[x2][y1 - 1] +
          onesum[x1 - 1][y1 - 1]) > 0;
}
int mincost(int x1, int y1, int x2, int y2) {
  if (dp[x1][y1][x2][y2] == -1) {
    if (!hasones(x1, y1, x2, y2)) {
      dp[x1][y1][x2][y2] = 0;
      return 0;
    }
    dp[x1][y1][x2][y2] = max(abs(x2 - x1) + 1, abs(y2 - y1) + 1);
    for (int i = x1; i < x2; i++) {
      dp[x1][y1][x2][y2] =
          min(dp[x1][y1][x2][y2],
              mincost(x1, y1, i, y2) + mincost(i + 1, y1, x2, y2));
    }
    for (int i = y1; i < y2; i++) {
      dp[x1][y1][x2][y2] =
          min(dp[x1][y1][x2][y2],
              mincost(x1, y1, x2, i) + mincost(x1, i + 1, x2, y2));
    }
  }
  return dp[x1][y1][x2][y2];
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> grid[i];
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (grid[i - 1][j - 1] == '#') onesum[i][j] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) onesum[i][j] += onesum[i - 1][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) onesum[i][j] += onesum[i][j - 1];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      for (int k = 0; k <= n; k++) {
        for (int l = 0; l <= n; l++) {
          dp[i][j][k][l] = -1;
        }
      }
    }
  }
  cout << mincost(1, 1, n, n) << '\n';
}
