#include <bits/stdc++.h>
using namespace std;
int n;
char a[55][55];
int f[55][55][55][55], s[55][55];
int nho[55][55][55][55];
int black(int x, int y, int u, int v) {
  return s[u][v] - s[x - 1][v] - s[u][y - 1] + s[x - 1][y - 1];
}
bool ok(int x, int y) {
  if (x < 1 || x > n || y < 1 || y > n) return false;
  return true;
}
int solve(int x, int y, int u, int v) {
  if (!ok(x, y) || !ok(u, v)) return 0;
  if (nho[x][y][u][v]) return f[x][y][u][v];
  nho[x][y][u][v] = 1;
  if (!black(x, y, u, v)) return 0;
  int &ans = f[x][y][u][v];
  ans = max(u - x + 1, v - y + 1);
  for (int k = x; k <= u - 1; ++k)
    ans = min(ans, solve(x, y, k, v) + solve(k + 1, y, u, v));
  for (int k = y; k <= v - 1; ++k)
    ans = min(ans, solve(x, y, u, k) + solve(x, k + 1, u, v));
  return ans;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[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] += (a[i][j] == '#');
    }
  cout << solve(1, 1, n, n);
}
