#include <bits/stdc++.h>
int n, f[52][52][52][52], s[52][52];
bool done[52][52][52][52];
void Prepare() {
  std::cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      char c;
      std::cin >> c;
      f[i][j][i][j] = (c == '#');
      done[i][j][i][j] = 1;
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + f[i][j][i][j];
    }
  }
}
int TD(const int x1, const int y1, const int x2, const int y2) {
  if (done[x1][y1][x2][y2]) return f[x1][y1][x2][y2];
  done[x1][y1][x2][y2] = 1;
  if (s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1] == 0)
    return (f[x1][y1][x2][y2] = 0);
  f[x1][y1][x2][y2] = std::max(x2 - x1 + 1, y2 - y1 + 1);
  for (int i = x1; i < x2; i++)
    f[x1][y1][x2][y2] =
        std::min(f[x1][y1][x2][y2], TD(x1, y1, i, y2) + TD(i + 1, y1, x2, y2));
  for (int j = y1; j < y2; j++)
    f[x1][y1][x2][y2] =
        std::min(f[x1][y1][x2][y2], TD(x1, y1, x2, j) + TD(x1, j + 1, x2, y2));
  return f[x1][y1][x2][y2];
}
void Process() { std::cout << TD(1, 1, n, n); }
int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  Prepare();
  Process();
}
