#include <bits/stdc++.h>
#pragma GCC optimize("2,Ofast,inline")
const long long N = 1e5 + 10;
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f;
const double eps = 1e-9;
using namespace std;
template <typename tp>
inline void read(tp &x) {
  x = 0;
  char c = getchar();
  bool f = 0;
  for (; c < '0' || c > '9'; f |= (c == '-'), c = getchar())
    ;
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar())
    ;
  if (f) x = -x;
}
int n, f[55][55][55][55];
char s[55][55];
int sum[55][55];
int num(int a, int b, int x, int y) {
  return sum[x][y] - sum[a - 1][y] - sum[x][b - 1] + sum[a - 1][b - 1];
}
int solve(int a, int b, int x, int y) {
  int &ret = f[a][b][x][y];
  if (ret)
    return ret;
  else
    ret = max(x - a + 1, y - b + 1);
  if (!num(a, b, x, y)) return ret = 0;
  for (int i = a; i < x; i++)
    ret = min(ret, solve(a, b, i, y) + solve(i + 1, b, x, y));
  for (int i = b; i < y; i++)
    ret = min(ret, solve(a, b, x, i) + solve(a, i + 1, x, y));
  return ret;
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
    for (int j = 1; j <= n; j++) sum[i][j] = sum[i][j - 1] + (s[i][j] == '#');
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) sum[i][j] += sum[i - 1][j];
  printf("%d\n", solve(1, 1, n, n));
  return 0;
}
