#include <bits/stdc++.h>
using namespace std;
bool grid[510][510];
int prefdb[510][510];
int iledb(pair<int, int> a, pair<int, int> b) {
  auto c = a;
  a = max(c, b);
  b = min(c, b);
  return prefdb[a.first][a.second] - prefdb[a.first][b.second - 1] -
         prefdb[b.first - 1][a.second] + prefdb[b.first - 1][b.second - 1];
}
int ilezl(pair<int, int> a, pair<int, int> b) {
  auto c = a;
  a = max(c, b);
  b = min(c, b);
  int sraka = a.first - b.first + 1;
  int sraka2 = a.second - b.second + 1;
  return sraka * sraka2 - iledb(a, b);
}
int father[510 * 510];
int getIndex[510][510];
int Find(int a) {
  if (father[a] == father[father[a]]) {
    return father[a];
  }
  father[a] = Find(father[a]);
  return father[a];
}
int groupsize[510 * 510];
void Union(int a, int b) {
  if (Find(a) != Find(b)) {
    father[Find(b)] = Find(a);
  }
}
int group[510][510];
int dp[510 * 510];
int wyn = 0;
void addDp(int i, int j) {
  int ti = i;
  int tj = j;
  if (grid[ti][tj]) {
    int a = group[ti][tj];
    if (dp[a] == 0) {
      wyn += groupsize[group[ti][tj]];
    }
    dp[a]++;
  }
  ti = i - 1;
  tj = j;
  if (grid[ti][tj]) {
    int a = group[ti][tj];
    if (dp[a] == 0) {
      wyn += groupsize[group[ti][tj]];
    }
    dp[a]++;
  }
  ti = i + 1;
  tj = j;
  if (grid[ti][tj]) {
    int a = group[ti][tj];
    if (dp[a] == 0) {
      wyn += groupsize[group[ti][tj]];
    }
    dp[a]++;
  }
  ti = i;
  tj = j - 1;
  if (grid[ti][tj]) {
    int a = group[ti][tj];
    if (dp[a] == 0) {
      wyn += groupsize[group[ti][tj]];
    }
    dp[a]++;
  }
  ti = i;
  tj = j + 1;
  if (grid[ti][tj]) {
    int a = group[ti][tj];
    if (dp[a] == 0) {
      wyn += groupsize[group[ti][tj]];
    }
    dp[a]++;
  }
}
void delDp(int i, int j) {
  int ti = i;
  int tj = j;
  if (grid[ti][tj]) {
    int a = group[ti][tj];
    if (dp[a] == 1) {
      wyn -= groupsize[group[ti][tj]];
    }
    dp[a]--;
  }
  ti = i - 1;
  tj = j;
  if (grid[ti][tj]) {
    int a = group[ti][tj];
    if (dp[a] == 1) {
      wyn -= groupsize[group[ti][tj]];
    }
    dp[a]--;
  }
  ti = i + 1;
  tj = j;
  if (grid[ti][tj]) {
    int a = group[ti][tj];
    if (dp[a] == 1) {
      wyn -= groupsize[group[ti][tj]];
    }
    dp[a]--;
  }
  ti = i;
  tj = j - 1;
  if (grid[ti][tj]) {
    int a = group[ti][tj];
    if (dp[a] == 1) {
      wyn -= groupsize[group[ti][tj]];
    }
    dp[a]--;
  }
  ti = i;
  tj = j + 1;
  if (grid[ti][tj]) {
    int a = group[ti][tj];
    if (dp[a] == 1) {
      wyn -= groupsize[group[ti][tj]];
    }
    dp[a]--;
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      getIndex[i][j] = (i - 1) * (n) + j - 1;
      father[getIndex[i][j]] = getIndex[i][j];
      char a;
      cin >> a;
      prefdb[i][j] = prefdb[i][j - 1];
      if (a == '.') {
        grid[i][j] = true;
        prefdb[i][j]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      prefdb[i][j] += prefdb[i - 1][j];
      if (grid[i][j]) {
        if (grid[i - 1][j]) {
          Union(getIndex[i][j], getIndex[i - 1][j]);
        }
        if (grid[i + 1][j]) {
          Union(getIndex[i][j], getIndex[i + 1][j]);
        }
        if (grid[i][j - 1]) {
          Union(getIndex[i][j], getIndex[i][j - 1]);
        }
        if (grid[i][j + 1]) {
          Union(getIndex[i][j], getIndex[i][j + 1]);
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (grid[i][j]) {
        group[i][j] = Find(getIndex[i][j]);
        groupsize[group[i][j]]++;
      } else {
        group[i][j] = 0;
      }
    }
  }
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      addDp(i, j);
    }
  }
  int wyn2 = wyn + ilezl(pair<int, int>(k, k), pair<int, int>(1, 1));
  for (int i = 1; i <= n - k + 1; i++) {
    pair<int, int> a;
    pair<int, int> b;
    a.first = i + k - 1;
    b.first = i;
    if (i % 2 == 1) {
      for (int j = 1; j <= n - k; j++) {
        a.second = j + k - 1;
        b.second = j;
        for (int ti = b.first; ti <= a.first; ti++) {
          addDp(ti, a.second + 1);
          delDp(ti, b.second);
        }
        wyn2 = max(wyn2, wyn + ilezl(pair<int, int>(a.first, a.second + 1),
                                     pair<int, int>(b.first, b.second + 1)));
      }
      a.second = n;
      b.second = n - k + 1;
    } else {
      for (int j = n - k + 1; j >= 2; j--) {
        a.second = j + k - 1;
        b.second = j;
        for (int ti = b.first; ti <= a.first; ti++) {
          delDp(ti, a.second);
          addDp(ti, b.second - 1);
        }
        wyn2 = max(wyn2, wyn + ilezl(pair<int, int>(a.first, a.second - 1),
                                     pair<int, int>(b.first, b.second - 1)));
      }
      a.second = k;
      b.second = 1;
    }
    if (i != n - k + 1) {
      for (int ti = b.second; ti <= a.second; ti++) {
        delDp(b.first, ti);
        addDp(a.first + 1, ti);
      }
      wyn2 = max(wyn2, wyn + ilezl(pair<int, int>(a.first + 1, a.second),
                                   pair<int, int>(b.first + 1, b.second)));
    }
  }
  cout << wyn2 << endl;
  return 0;
}
