#include <bits/stdc++.h>
using namespace std;
const int N = 55;
const int INF = 1000000000;
char a[N][N];
int n;
int dp[N][N][N][N];
int mn_xx[N][N][N];
int mn_yy[N][N][N];
int mx_xx[N][N][N];
int mx_yy[N][N][N];
int mn_xxx[N][N][N];
int mn_yyy[N][N][N];
int mx_xxx[N][N][N];
int mx_yyy[N][N][N];
int go(int x1, int mezhdy, int x2, int nami) {
  if (x1 > x2 || mezhdy > nami) return 0;
  if (dp[x1][mezhdy][x2][nami] != -1) return dp[x1][mezhdy][x2][nami];
  int mn_x = INF;
  int mn_y = INF;
  int mx_x = 0;
  int mx_y = 0;
  if (x2 - x1 <= nami - mezhdy)
    for (int i = x1; i <= x2; i++) {
      mn_x = min(mn_x, mn_xx[mezhdy][nami][i]);
      mn_y = min(mn_y, mn_yy[mezhdy][nami][i]);
      mx_x = max(mx_x, mx_xx[mezhdy][nami][i]);
      mx_y = max(mx_y, mx_yy[mezhdy][nami][i]);
    }
  else
    for (int j = mezhdy; j <= nami; j++) {
      mn_x = min(mn_x, mn_xxx[x1][x2][j]);
      mn_y = min(mn_y, mn_yyy[x1][x2][j]);
      mx_x = max(mx_x, mx_xxx[x1][x2][j]);
      mx_y = max(mx_y, mx_yyy[x1][x2][j]);
    }
  int res = max(mx_x - mn_x + 1, mx_y - mn_y + 1);
  if (mn_x == INF) {
    res = 0;
    return dp[x1][mezhdy][x2][nami] = res;
  }
  for (int i = x1; i < x2; i++)
    res = min(res, go(x1, mezhdy, i, nami) + go(i + 1, mezhdy, x2, nami));
  for (int j = mezhdy; j < nami; j++)
    res = min(res, go(x1, mezhdy, x2, j) + go(x1, j + 1, x2, nami));
  return dp[x1][mezhdy][x2][nami] = res;
}
int main() {
  ios_base::sync_with_stdio(0);
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      for (int k = 0; k < N; k++) {
        mn_xx[i][j][k] = INF;
        mn_yy[i][j][k] = INF;
        mn_xxx[i][j][k] = INF;
        mn_yyy[i][j][k] = INF;
      }
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
      if (a[i][j] == '#') {
        mn_xx[j][j][i] = i;
        mx_xx[j][j][i] = i;
        mn_yy[j][j][i] = j;
        mx_yy[j][j][i] = j;
        mn_xxx[i][i][j] = i;
        mx_xxx[i][i][j] = i;
        mn_yyy[i][i][j] = j;
        mx_yyy[i][i][j] = j;
      }
    }
  for (int j1 = 0; j1 < n; j1++)
    for (int j2 = j1 + 1; j2 < n; j2++)
      for (int i = 0; i < n; i++) {
        mn_xx[j1][j2][i] =
            min(mn_xx[j1][j2][i], min(mn_xx[j1][j2 - 1][i], mn_xx[j2][j2][i]));
        mx_xx[j1][j2][i] =
            max(mx_xx[j1][j2][i], max(mx_xx[j1][j2 - 1][i], mx_xx[j2][j2][i]));
        mn_yy[j1][j2][i] =
            min(mn_yy[j1][j2][i], min(mn_yy[j1][j2 - 1][i], mn_yy[j2][j2][i]));
        mx_yy[j1][j2][i] =
            max(mx_yy[j1][j2][i], max(mx_yy[j1][j2 - 1][i], mx_yy[j2][j2][i]));
      }
  for (int i1 = 0; i1 < n; i1++)
    for (int i2 = i1 + 1; i2 < n; i2++)
      for (int j = 0; j < n; j++) {
        mn_xxx[i1][i2][j] = min(mn_xxx[i1][i2][j],
                                min(mn_xxx[i1][i2 - 1][j], mn_xxx[i2][i2][j]));
        mx_xxx[i1][i2][j] = max(mx_xxx[i1][i2][j],
                                max(mx_xxx[i1][i2 - 1][j], mx_xxx[i2][i2][j]));
        mn_yyy[i1][i2][j] = min(mn_yyy[i1][i2][j],
                                min(mn_yyy[i1][i2 - 1][j], mn_yyy[i2][i2][j]));
        mx_yyy[i1][i2][j] = max(mx_yyy[i1][i2][j],
                                max(mx_yyy[i1][i2 - 1][j], mx_yyy[i2][i2][j]));
      }
  cout << go(0, 0, n - 1, n - 1);
}
