#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
};
vector<node> w[55];
int n, ans;
char mp[55][55];
int cnt[55][55];
bool mark[55][55];
int dp[55][55][55][55];
int dfs(int x1, int y1, int x2, int y2) {
  int &res = dp[x1][y1][x2][y2];
  if (~res) return res;
  if (cnt[x2][y2] - cnt[x1 - 1][y2] - cnt[x2][y1 - 1] + cnt[x1 - 1][y1 - 1] ==
      0)
    return res = 0;
  res = max(x2 - x1 + 1, y2 - y1 + 1);
  for (int i = x1; i < x2; i++)
    res = min(res, dfs(x1, y1, i, y2) + dfs(i + 1, y1, x2, y2));
  for (int i = y1; i < y2; i++)
    res = min(res, dfs(x1, y1, x2, i) + dfs(x1, i + 1, x2, y2));
  return res;
}
int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", mp[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      cnt[i][j] =
          cnt[i][j - 1] + cnt[i - 1][j] - cnt[i - 1][j - 1] + (mp[i][j] == '#');
  printf("%d\n", dfs(1, 1, n, n));
  return 0;
}
