#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0LL, f = 1LL;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1LL;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = 10LL * x + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 64;
int dp[N][N][N][N];
int a[N][N];
char str[N];
int area(int x, int y, int xx, int yy) {
  return a[xx][yy] - a[x - 1][yy] - a[xx][y - 1] + a[x - 1][y - 1];
}
int dfs(int lx, int rx, int ly, int ry) {
  if (area(lx, ly, rx, ry) == 0) {
    return 0;
  }
  if (dp[lx][rx][ly][ry] != -1) {
    return dp[lx][rx][ly][ry];
  }
  int &f = dp[lx][rx][ly][ry];
  f = max(rx - lx + 1, ry - ly + 1);
  for (int i = (lx); i <= (rx - 1); i++)
    f = min(f, dfs(lx, i, ly, ry) + dfs(i + 1, rx, ly, ry));
  for (int i = (ly); i <= (ry - 1); i++)
    f = min(f, dfs(lx, rx, ly, i) + dfs(lx, rx, i + 1, ry));
  return f;
}
int main() {
  int n = read();
  for (int i = (1); i <= (n); i++) {
    scanf("%s", str + 1);
    for (int j = (1); j <= (n); j++) {
      a[i][j] = a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1] + (str[j] == '#');
    }
  }
  memset(dp, -1, sizeof(dp));
  cout << dfs(1, n, 1, n) << endl;
  return 0;
}
