#include <bits/stdc++.h>
using namespace std;
int n, k, i, j, connected[501][501], parent, tatko[501][501], maxx, ii, jj,
    dodadi[125001], broj;
char niza[501][501];
bool visited[501][501];
int main() {
  for (i = 0; i < 125001; i++) {
    dodadi[i] = 0;
  }
  parent = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      cin >> niza[i][j];
      tatko[i][j] = -1;
      visited[i][j] = false;
      connected[i][j] = 0;
    }
  }
  queue<pair<int, int> > flood;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if ((visited[i][j] == false) && (niza[i][j] == '.')) {
        flood.push(make_pair(i, j));
        visited[i][j] = true;
        int total = 1;
        while (!flood.empty()) {
          pair<int, int> temp = flood.front();
          flood.pop();
          int row = temp.first;
          int column = temp.second;
          if ((row - 1 >= 0) && (visited[row - 1][column] == false) &&
              (niza[row - 1][column] == '.')) {
            flood.push(make_pair(row - 1, column));
            visited[row - 1][column] = true;
            total++;
          }
          if ((row + 1 < n) && (visited[row + 1][column] == false) &&
              (niza[row + 1][column] == '.')) {
            flood.push(make_pair(row + 1, column));
            visited[row + 1][column] = true;
            total++;
          }
          if ((column - 1 >= 0) && (visited[row][column - 1] == false) &&
              (niza[row][column - 1] == '.')) {
            flood.push(make_pair(row, column - 1));
            visited[row][column - 1] = true;
            total++;
          }
          if ((column + 1 < n) && (visited[row][column + 1] == false) &&
              (niza[row][column + 1] == '.')) {
            flood.push(make_pair(row, column + 1));
            visited[row][column + 1] = true;
            total++;
          }
        }
        connected[i][j] = total;
        tatko[i][j] = parent;
        flood.push(make_pair(i, j));
        while (!flood.empty()) {
          pair<int, int> temp = flood.front();
          flood.pop();
          int row = temp.first;
          int column = temp.second;
          if ((row - 1 >= 0) && (connected[row - 1][column] == 0) &&
              (niza[row - 1][column] == '.')) {
            flood.push(make_pair(row - 1, column));
            connected[row - 1][column] = total;
            tatko[row - 1][column] = parent;
          }
          if ((row + 1 < n) && (connected[row + 1][column] == 0) &&
              (niza[row + 1][column] == '.')) {
            flood.push(make_pair(row + 1, column));
            connected[row + 1][column] = total;
            tatko[row + 1][column] = parent;
          }
          if ((column - 1 >= 0) && (connected[row][column - 1] == 0) &&
              (niza[row][column - 1] == '.')) {
            flood.push(make_pair(row, column - 1));
            connected[row][column - 1] = total;
            tatko[row][column - 1] = parent;
          }
          if ((column + 1 < n) && (connected[row][column + 1] == 0) &&
              (niza[row][column + 1] == '.')) {
            flood.push(make_pair(row, column + 1));
            connected[row][column + 1] = total;
            tatko[row][column + 1] = parent;
          }
        }
        parent++;
      }
    }
  }
  int maxx = 0;
  int total = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if ((i + k > n) || (j + k > n)) continue;
      if (j == 0) {
        total = 0;
        for (ii = 0; ii < 125001; ii++) {
          dodadi[ii] = 0;
        }
        for (ii = i; ii < i + k; ii++) {
          for (jj = j; jj < j + k; jj++) {
            if (niza[ii][jj] == 'X') {
              total++;
              continue;
            }
            broj = tatko[ii][jj];
            if (dodadi[broj] == 0) {
              total = total + connected[ii][jj];
            }
            dodadi[broj]++;
          }
        }
      } else {
        jj = j + k - 1;
        for (ii = i; ii < i + k; ii++) {
          if (niza[ii][jj] == 'X') {
            total++;
            continue;
          }
          broj = tatko[ii][jj];
          if (dodadi[broj] == 0) {
            total = total + connected[ii][jj];
          }
          dodadi[broj]++;
        }
        jj = j - 1;
        for (ii = i; ii < i + k; ii++) {
          if (niza[ii][jj] == 'X') {
            total--;
            continue;
          }
          broj = tatko[ii][jj];
          dodadi[broj]--;
          if (dodadi[broj] == 0) {
            total = total - connected[ii][jj];
          }
        }
      }
      int curr = 0;
      if (i > 0) {
        ii = i - 1;
        for (jj = j; jj < j + k; jj++) {
          broj = tatko[ii][jj];
          if (dodadi[broj] == 0) {
            curr = curr + connected[ii][jj];
          }
          dodadi[broj]++;
        }
      }
      if (i < n - 1) {
        ii = i + k;
        for (jj = j; jj < j + k; jj++) {
          broj = tatko[ii][jj];
          if (dodadi[broj] == 0) {
            curr = curr + connected[ii][jj];
          }
          dodadi[broj]++;
        }
      }
      if (j > 0) {
        jj = j - 1;
        for (ii = i; ii < i + k; ii++) {
          broj = tatko[ii][jj];
          if (dodadi[broj] == 0) {
            curr = curr + connected[ii][jj];
          }
          dodadi[broj]++;
        }
      }
      if (j < n - 1) {
        jj = j + k;
        for (ii = i; ii < i + k; ii++) {
          broj = tatko[ii][jj];
          if (dodadi[broj] == 0) {
            curr = curr + connected[ii][jj];
          }
          dodadi[broj]++;
        }
      }
      if (curr + total > maxx) {
        maxx = curr + total;
      }
      if (i > 0) {
        ii = i - 1;
        for (jj = j; jj < j + k; jj++) {
          broj = tatko[ii][jj];
          dodadi[broj]--;
        }
      }
      if (i < n - 1) {
        ii = i + k;
        for (jj = j; jj < j + k; jj++) {
          broj = tatko[ii][jj];
          dodadi[broj]--;
        }
      }
      if (j > 0) {
        jj = j - 1;
        for (ii = i; ii < i + k; ii++) {
          broj = tatko[ii][jj];
          dodadi[broj]--;
        }
      }
      if (j < n - 1) {
        jj = j + k;
        for (ii = i; ii < i + k; ii++) {
          broj = tatko[ii][jj];
          dodadi[broj]--;
        }
      }
    }
  }
  cout << maxx;
  return 0;
}
