#include <bits/stdc++.h>
using namespace std;
int dp[52][52][52][52] = {};
int main() {
  int N;
  cin >> N;
  vector<vector<char>> F(N + 1, vector<char>(N + 1, 0));
  vector<vector<int>> S(N + 1, vector<int>(N + 1, 0));
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++) {
      cin >> F[i][j];
      S[i][j] = (F[i][j] == '#');
    }
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++) S[i][j] += S[i][j - 1];
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++) S[i][j] += S[i - 1][j];
  auto getsum = [&](int x1, int y1, int x2, int y2) {
    return S[x2][y2] - S[x1 - 1][y2] - S[x2][y1 - 1] + S[x1 - 1][y1 - 1];
  };
  int inf = 1e9;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)
      for (int k = 1; k <= N; k++)
        for (int l = 1; l <= N; l++) dp[i][j][k][l] = inf;
  function<int(int, int, int, int)> rec = [&](int x1, int y1, int x2, int y2) {
    if (x2 < x1 || y2 < y1) return dp[x1][y1][x2][y2] = 0;
    if (getsum(x1, y1, x2, y2) == 0) return dp[x1][y1][x2][y2] = 0;
    if (dp[x1][y1][x2][y2] != inf) return dp[x1][y1][x2][y2];
    int dx = x2 - x1 + 1, dy = y2 - y1 + 1;
    int res = max(dx, dy);
    for (int i = x1; i <= x2; i++) {
      if (getsum(i, y1, i, y2) == 0)
        res = min(res, rec(x1, y1, i - 1, y2) + rec(i + 1, y1, x2, y2));
    }
    for (int j = y1; j <= y2; j++) {
      if (getsum(x1, j, x2, j) == 0)
        res = min(res, rec(x1, y1, x2, j - 1) + rec(x1, j + 1, x2, y2));
    }
    return dp[x1][y1][x2][y2] = res;
  };
  cout << rec(1, 1, N, N) << endl;
}
