#include <bits/stdc++.h>
using namespace std;
const string nameFile = "test";
ifstream in(nameFile + ".in");
ofstream out(nameFile + ".out");
const int oo = 2e9;
int dp[52][52][52][52];
int a[52][52];
char ch;
int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(dp, oo, 52 * 52 * 52 * 52 * sizeof(int));
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      cin >> ch;
      a[i][j] = a[i][j - 1] + a[i - 1][j] - a[i - 1][j - 1] + (int)(ch == '#');
    }
  for (int x2 = 1; x2 <= n; x2++)
    for (int y2 = 1; y2 <= n; y2++)
      for (int x1 = x2; x1 >= 1; x1--)
        for (int y1 = y2; y1 >= 1; y1--) {
          if (a[x2][y2] + a[x1 - 1][y1 - 1] - a[x2][y1 - 1] - a[x1 - 1][y2] ==
              0)
            dp[x1][y1][x2][y2] = 0;
          else {
            dp[x1][y1][x2][y2] = max(y2 - y1 + 1, x2 - x1 + 1);
            for (int k = x1; k <= x2; k++) {
              dp[x1][y1][x2][y2] =
                  min(dp[x1][y1][x2][y2],
                      dp[x1][y1][k][y2] + dp[k + 1][y1][x2][y2]);
            }
            for (int k = y1; k <= y2; k++) {
              dp[x1][y1][x2][y2] =
                  min(dp[x1][y1][x2][y2],
                      dp[x1][y1][x2][k] + dp[x1][k + 1][x2][y2]);
            }
          }
        }
  cout << dp[1][1][n][n];
}
