#include <bits/stdc++.h>
using namespace std;
int n, f[55][55][55][55];
char s[55][55];
int dfs(int x, int y, int xx, int yy) {
  if (~f[x][y][xx][yy]) return f[x][y][xx][yy];
  if (x == xx && y == yy) {
    if (s[x][y] == '#')
      return 1;
    else
      return 0;
  }
  f[x][y][xx][yy] = max(xx - x + 1, yy - y + 1);
  for (int i = x; i < xx; i++)
    f[x][y][xx][yy] =
        min(f[x][y][xx][yy], dfs(x, y, i, yy) + dfs(i + 1, y, xx, yy));
  for (int i = y; i < yy; i++)
    f[x][y][xx][yy] =
        min(f[x][y][xx][yy], dfs(x, y, xx, i) + dfs(x, i + 1, xx, yy));
  return f[x][y][xx][yy];
}
signed main() {
  cin >> n;
  memset(f, -1, sizeof(f));
  for (int i = 1; i <= n; i++) cin >> s[i] + 1;
  printf("%d", dfs(1, 1, n, n));
}
