#include <bits/stdc++.h>
using namespace std;
enum class Colors { WHITE, GREY, BLACK };
std::vector<std::pair<int, int>> get_neighbours(
    std::vector<std::vector<char>>& maze, int i, int j) {
  std::vector<std::pair<int, int>> indices;
  if (j - 1 >= 0 && j - 1 < maze.size()) {
    indices.push_back(std::make_pair(i, j - 1));
  }
  if (j + 1 >= 0 && j + 1 < maze.size()) {
    indices.push_back(std::make_pair(i, j + 1));
  }
  if (i + 1 >= 0 && i + 1 < maze.size()) {
    indices.push_back(std::make_pair(i + 1, j));
  }
  if (i - 1 >= 0 && i - 1 < maze.size()) {
    indices.push_back(std::make_pair(i - 1, j));
  }
  return indices;
};
int bfs(std::vector<std::vector<char>>& maze,
        std::queue<std::pair<int, int>>& q,
        std::vector<std::vector<int>>& components,
        std::vector<std::vector<Colors>>& colors, int marker) {
  int total = 0;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    auto i = p.first;
    auto j = p.second;
    if (colors[i][j] != Colors::BLACK) {
      components[i][j] = marker;
      auto neighbours = get_neighbours(maze, i, j);
      for (auto it = neighbours.begin(); it != neighbours.end(); ++it) {
        if (maze[it->first][it->second] == '.' &&
            colors[it->first][it->second] == Colors::WHITE) {
          colors[it->first][it->second] = Colors::GREY;
          q.push(*it);
        }
      }
    }
    colors[i][j] = Colors::BLACK;
    total += 1;
  }
  return total;
}
std::pair<std::vector<std::vector<int>>, std::vector<int>> get_components(
    std::vector<std::vector<char>>& maze) {
  std::vector<std::vector<int>> components(maze.size(),
                                           vector<int>(maze.size(), -1));
  std::vector<std::vector<Colors>> colors(
      maze.size(), vector<Colors>(maze.size(), Colors::WHITE));
  std::vector<int> markers;
  std::queue<std::pair<int, int>> q;
  for (int i = 0; i < maze.size(); ++i) {
    for (int j = 0; j < maze.size(); ++j) {
      if (colors[i][j] == Colors::WHITE && maze[i][j] == '.') {
        q.push(std::make_pair(i, j));
        markers.push_back(
            bfs(maze, q, components, colors, int(markers.size())));
      }
    }
  }
  return std::make_pair(components, markers);
};
std::vector<std::pair<int, int>> get_outer_square(int i, int j, int k) {
  std::vector<std::pair<int, int>> points;
  for (int p = j; p < j + k; ++p) {
    points.push_back(std::make_pair(i - 1, p));
    points.push_back(std::make_pair(i + k, p));
  }
  for (int ii = i; ii < i + k; ++ii) {
    for (int jj = j - 1; jj < j + k + 1; ++jj) {
      points.push_back(std::make_pair(ii, jj));
    }
  }
  return points;
};
std::vector<std::pair<int, int>> get_inside(int i, int j, int k) {
  std::vector<std::pair<int, int>> points;
  for (int ii = i; ii < i + k; ++ii) {
    for (int jj = j; jj < j + k; ++jj) {
      points.push_back(std::make_pair(ii, jj));
    }
  }
  return points;
}
int update(std::vector<std::vector<int>>& components, vector<int>& markers,
           vector<int>& state, int ii, int jj, bool down, int add) {
  int cells_add = 0;
  if (down) {
    int k = ii;
    ii = jj;
    jj = k;
  }
  int c = components[ii][jj];
  if (add == 1) {
    if (c != -1) {
      if (state[c] == 0) {
        cells_add += markers[c];
      }
      state[c] += 1;
    }
  } else {
    if (c != -1) {
      state[c] -= 1;
      if (state[c] == 0) {
        cells_add -= markers[c];
      }
    }
  }
  return cells_add;
}
int update_x(std::vector<std::vector<char>>& maze, int ii, int jj, bool down) {
  if (down) {
    int k = ii;
    ii = jj;
    jj = k;
  }
  return int(maze[ii][jj] == 'X');
}
int fill_components(std::vector<std::vector<char>>& maze,
                    std::vector<std::vector<int>>& components,
                    std::vector<int>& markers, std::vector<int>& state, int i,
                    int j, int k, bool down, int right) {
  int cells_add = 0;
  int jk = j + k;
  int jk_1 = jk + 1;
  int j_1 = j - 1;
  int ik = i + k;
  for (int ii = i; ii < ik; ++ii) {
    if (ii >= 0 && ii < maze.size()) {
      if (jk_1 < maze.size()) {
        cells_add += update(components, markers, state, ii, jk_1, down, right);
      }
      if (j_1 >= 0) {
        cells_add += update(components, markers, state, ii, j_1, down, -right);
      }
    }
    cells_add += right * update_x(maze, ii, jk, down);
    cells_add -= right * update_x(maze, ii, j, down);
  }
  auto elements = {i - 1, ik};
  for (auto ii = elements.begin(); ii != elements.end(); ++ii) {
    if (*ii >= 0 && *ii < maze.size()) {
      if (jk < maze.size()) {
        cells_add += update(components, markers, state, *ii, jk, down, right);
      }
      if (j >= 0) {
        cells_add += update(components, markers, state, *ii, j, down, -right);
      }
    }
  }
  return cells_add;
}
int find_max(std::vector<std::vector<char>>& maze,
             std::vector<std::vector<int>>& components,
             std::vector<int>& markers, int k) {
  auto state = std::vector<int>(markers.size(), 0);
  int current_value = 0;
  auto inside_indices = get_inside(0, 0, k);
  for (auto it = inside_indices.begin(); it != inside_indices.end(); ++it) {
    current_value += update_x(maze, it->first, it->second, false);
  }
  auto perimeter_indices = get_outer_square(0, 0, k);
  for (auto it = perimeter_indices.begin(); it != perimeter_indices.end();
       ++it) {
    int ii = it->first;
    int jj = it->second;
    if (ii >= 0 && ii < maze.size()) {
      if (jj >= 0 && jj < maze.size()) {
        current_value += update(components, markers, state, ii, jj, false, 1);
      }
    }
  }
  int flag = -1;
  int max_values = current_value;
  int ii;
  int jj;
  for (int i = 0; i < maze.size() - k + 1; ++i) {
    for (int j = 0; j < maze.size() - k; ++j) {
      if (flag == 1) {
        ii = i;
        jj = int(maze.size() - j - k - 1);
      } else {
        ii = i;
        jj = j;
      }
      current_value += fill_components(maze, components, markers, state, ii, jj,
                                       k, false, -flag);
      max_values = max(max_values, current_value);
    }
    if (i != maze.size() - k) {
      if (flag == 1) {
        ii = 0;
        jj = i;
      } else {
        ii = int(maze.size() - k);
        jj = i;
      }
      current_value +=
          fill_components(maze, components, markers, state, ii, jj, k, true, 1);
      flag = -flag;
      max_values = max(max_values, current_value);
    }
  }
  return max_values;
}
int main() {
  std::string line;
  std::getline(std::cin, line);
  std::stringstream ss(line);
  size_t n;
  ss >> n;
  size_t k;
  ss >> k;
  std::vector<std::vector<char>> maze(n, std::vector<char>(n));
  for (int i = 0; i < n; ++i) {
    std::getline(std::cin, line);
    for (int j = 0; j < line.size(); ++j) {
      maze[i][j] = line[j];
    }
  }
  auto p = get_components(maze);
  auto components = p.first;
  auto markers = p.second;
  std::cout << find_max(maze, components, markers, int(k)) << std::endl;
  return 0;
}
