#include <bits/stdc++.h>
using namespace std;
template <typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) {
  return os << '(' << pai.first << ' ' << pai.second << ')';
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
  cout << '[';
  for (auto p : v) cout << p << ",";
  cout << "]";
  return os;
}
template <typename T, typename V>
ostream &operator<<(ostream &os, const set<T, V> v) {
  cout << "{";
  for (auto p : v) cout << p << ",";
  cout << "}";
  return os;
}
template <typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
  cout << "{";
  for (auto p : v) cout << p << ",";
  cout << "}";
  return os;
}
template <typename T>
void get_max(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void get_min(T &a, T b) {
  a = min(a, b);
}
int N;
char board[50][51];
int dp[50][50][50][50];
int main(void) {
  iostream::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cin >> N;
  for (int i = 0, _i = (N); i < _i; i++) cin >> board[i];
  for (int i = 0, _i = (N); i < _i; i++)
    for (int j = 0, _j = (N); j < _j; j++)
      dp[i][i][j][j] = (board[i][j] == '#');
  for (int x = 0, _x = (N); x < _x; x++)
    for (int y = 0, _y = (N); y < _y; y++)
      if (x + y)
        for (int i = 0, _i = (N - x); i < _i; i++)
          for (int j = 0, _j = (N - y); j < _j; j++) {
            int &v = dp[i][i + x][j][j + y];
            v = max(x, y) + 1;
            for (int z = 0, _z = (x); z < _z; z++)
              get_min(v,
                      dp[i][i + z][j][j + y] + dp[i + z + 1][i + x][j][j + y]);
            for (int z = 0, _z = (y); z < _z; z++)
              get_min(v,
                      dp[i][i + x][j][j + z] + dp[i][i + x][j + z + 1][j + y]);
            0;
          }
  cout << dp[0][N - 1][0][N - 1] << '\n';
}
