#include <bits/stdc++.h>
using namespace std;
int n;
int a[52][52];
int dp[52][52][52][52];
int go(int x1, int y1, int x2, int y2) {
  int sum = a[x2][y2] - a[x1 - 1][y2] - a[x2][y1 - 1] + a[x1 - 1][y1 - 1];
  if (sum <= 0) return 0;
  int &res = dp[x1][y1][x2][y2];
  if (res != -1) return res;
  res = max(x2 - x1, y2 - y1) + 1;
  for (int x = x1; x < x2; x++)
    res = min(res, go(x1, y1, x, y2) + go(x + 1, y1, x2, y2));
  for (int y = y1; y < y2; y++)
    res = min(res, go(x1, y1, x2, y) + go(x1, y + 1, x2, y2));
  return res;
}
void solve() {
  cin >> n;
  for (int i = 1; i < n + 1; i++)
    for (int j = 1; j < n + 1; j++) {
      char c;
      cin >> c;
      a[i][j] = (c == '#');
    }
  for (int i = 1; i < n + 1; i++)
    for (int j = 1; j < n + 1; j++)
      a[i][j] += a[i][j - 1] + a[i - 1][j] - a[i - 1][j - 1];
  memset(dp, -1, sizeof dp);
  cout << go(1, 1, n, n);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    solve();
  }
  return 0;
}
