#include <bits/stdc++.h>
using namespace std;
int n, dp[55][55][55][55];
char mp[55][55];
int dfs(int x1, int y1, int x2, int y2) {
  if (dp[x1][y1][x2][y2] != -1) return dp[x1][y1][x2][y2];
  int ans = max(y2 - y1 + 1, x2 - x1 + 1);
  for (int i = x1; i < x2; i++) {
    ans = min(ans, dfs(x1, y1, i, y2) + dfs(i + 1, y1, x2, y2));
  }
  for (int i = y1; i < y2; i++) {
    ans = min(ans, dfs(x1, y1, x2, i) + dfs(x1, i + 1, x2, y2));
  }
  dp[x1][y1][x2][y2] = ans;
  return ans;
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> mp[i] + 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) dp[i][j][i][j] = (mp[i][j] == '#');
  }
  cout << dfs(1, 1, n, n);
}
