#include <bits/stdc++.h>
using namespace std;
const int N = 55;
string str[N];
int dp[N][N][N][N];
int f(int x1, int y1, int x2, int y2) {
  if (x1 == x2 && y1 == y2) return str[x1][y1] == '#';
  if (~dp[x1][y1][x2][y2]) return dp[x1][y1][x2][y2];
  int res = max(x2 - x1 + 1, y2 - y1 + 1);
  for (int i = x1; i < x2; i++)
    res = min(res, f(x1, y1, i, y2) + f(i + 1, y1, x2, y2));
  for (int i = y1; i < y2; i++)
    res = min(res, f(x1, y1, x2, i) + f(x1, i + 1, x2, y2));
  return dp[x1][y1][x2][y2] = res;
}
int main() {
  int n;
  cin >> n;
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < n; i++) cin >> str[i];
  cout << f(0, 0, n - 1, n - 1) << endl;
}
