#include <bits/stdc++.h>
using namespace std;
int n, dp[55][55][55][55], s[55][55];
bool memo[55][55][55][55];
int calc(int u, int v, int x, int y) {
  if (memo[u][v][x][y]) return dp[u][v][x][y];
  memo[u][v][x][y] = true;
  int &res = dp[u][v][x][y];
  res = max(x - u + 1, y - v + 1);
  int sum = s[x][y] - s[x][v - 1] - s[u - 1][y] + s[u - 1][v - 1];
  if (sum == 0)
    return res = 0;
  else if (sum == (x - u + 1) * (y - v + 1))
    return res;
  for (int i = u; i < x; ++i)
    res = min(res, calc(u, v, i, y) + calc(i + 1, v, x, y));
  for (int i = v; i < y; ++i)
    res = min(res, calc(u, v, x, i) + calc(u, i + 1, x, y));
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) {
      char c;
      cin >> c;
      s[i][j] = s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1] + (c == '#');
    }
  cout << calc(1, 1, n, n);
  return 0;
}
