#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int r[N][N], c[N][N], s[N][N], f[N][N][N][N], n;
int sol(int x1, int y1, int x2, int y2) {
  if (x1 <= 0 || x2 <= 0 || y1 <= 0 || y2 <= 0 || x1 > n || x2 > n || y1 > n ||
      y2 > n || x1 > x2 || y1 > y2)
    return 0;
  if (f[x1][y1][x2][y2] >= 0) return f[x1][y1][x2][y2];
  if (s[x2][y2] + s[x1 - 1][y1 - 1] - s[x2][y1 - 1] - s[x1 - 1][y2] ==
      (y2 - y1 + 1) * (x2 - x1 + 1))
    return f[x1][y1][x2][y2] = max(x2 - x1 + 1, y2 - y1 + 1);
  if (s[x2][y2] + s[x1 - 1][y1 - 1] - s[x2][y1 - 1] - s[x1 - 1][y2] == 0)
    return f[x1][y1][x2][y2] = 0;
  int ans = max(x2 - x1 + 1, y2 - y1 + 1);
  for (int i = x1; i <= x2; i++) {
    if (r[i][y2] - r[i][y1 - 1] == 0)
      ans = min(ans, sol(x1, y1, i - 1, y2) + sol(i + 1, y1, x2, y2));
  }
  for (int j = y1; j <= y2; j++) {
    if (c[x2][j] - c[x1 - 1][j] == 0)
      ans = min(ans, sol(x1, y1, x2, j - 1) + sol(x1, j + 1, x2, y2));
  }
  return f[x1][y1][x2][y2] = ans;
}
int main() {
  cin >> n;
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (n); j++) {
      char ch;
      cin >> ch;
      if (ch == '#') s[i][j] = 1;
    }
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (n); j++) r[i][j] = r[i][j - 1] + s[i][j];
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (n); j++) c[i][j] = c[i - 1][j] + s[i][j];
  for (int i = (1); i <= (n); i++)
    for (int j = (1); j <= (n); j++)
      s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
  memset(f, -63, sizeof(f));
  cout << sol(1, 1, n, n) << endl;
  return 0;
}
