#include <bits/stdc++.h>
using namespace std;
const short int N = 51;
short int dp[N][N][N][N];
short int my_min(short int a, short int b) {
  if (a < b) return a;
  return b;
}
void solve() {
  short int n;
  cin >> n;
  for (short int i = 0; i < (short int)n; ++i)
    for (short int j = 0; j < (short int)n; ++j) {
      char c;
      cin >> c;
      dp[i][j][1][1] = (c == '#');
    }
  for (short int i = 1; i <= (short int)n; ++i)
    for (short int j = 1; j <= (short int)n; ++j)
      for (short int x = 0; x < (short int)n - i + 1; ++x)
        for (short int y = 0; y < (short int)n - j + 1; ++y) {
          if (i == 1 && j == 1) continue;
          dp[x][y][i][j] = max(i, j);
          if (i > j)
            for (short int cnt = 0; cnt < (short int)i; ++cnt) {
              if (!dp[x + cnt][y][1][j])
                dp[x][y][i][j] = my_min(
                    dp[x][y][i][j],
                    dp[x][y][cnt][j] + dp[x + cnt + 1][y][i - cnt - 1][j]);
            }
          else
            for (short int cnt = 0; cnt < (short int)j; ++cnt)
              if (!dp[x][y + cnt][i][1])
                dp[x][y][i][j] = my_min(
                    dp[x][y][i][j],
                    dp[x][y][i][cnt] + dp[x][y + cnt + 1][i][j - cnt - 1]);
        }
  cout << dp[0][0][n][n];
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
