#include <bits/stdc++.h>
using namespace std;
template <class P, class Q>
ostream& operator<<(ostream& stream, pair<P, Q> v) {
  stream << "(" << v.first << ',' << v.second << ")";
  return stream;
}
template <class T>
ostream& operator<<(ostream& stream, const vector<T> v) {
  stream << "[ ";
  for (int i = 0; i < (int)v.size(); i++) stream << v[i] << " ";
  stream << "]";
  return stream;
}
template <class T>
T smin(T& a, T b) {
  if (a > b) a = b;
  return a;
}
template <class T>
T smax(T& a, T b) {
  if (a < b) a = b;
  return a;
}
int dp[55][55][55][55];
char s[64][64];
int S[64][64];
int main(void) {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> (s[i] + 1);
  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] + (s[i][j] == '#');
  for (int a = 1; a <= n; ++a)
    for (int b = 1; b <= n; ++b)
      for (int c = a; c <= n; ++c)
        for (int d = b; d <= n; ++d) {
          if (S[c][d] + S[a - 1][b - 1] == S[a - 1][d] + S[c][b - 1])
            dp[a][b][c][d] = 0;
          else
            dp[a][b][c][d] = max(c - a + 1, d - b + 1);
        }
  for (int len1 = 0; len1 <= n; ++len1)
    for (int len2 = 0; len2 <= n; ++len2)
      for (int a = 1; a + len1 <= n; ++a)
        for (int b = 1; b + len2 <= n; ++b) {
          for (int len = 0; len < len1; ++len)
            smin(dp[a][b][a + len1][b + len2],
                 dp[a][b][a + len][b + len2] +
                     dp[a + len + 1][b][a + len1][b + len2]);
          for (int len = 0; len < len2; ++len)
            smin(dp[a][b][a + len1][b + len2],
                 dp[a][b][a + len1][b + len] +
                     dp[a][b + len + 1][a + len1][b + len2]);
        }
  cout << dp[1][1][n][n] << '\n';
  return 0;
}
