#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[505][505];
bool vis[505][505];
long long cntc;
long long id[505][505];
long long cnt[500 * 505];
long long dx[] = {1, -1, 0, 0};
long long dy[] = {0, 0, -1, 1};
long long curT;
long long added[500 * 505];
bool inside(long long x, long long y) {
  if (x >= n || y >= n) return false;
  if (x < 0 || y < 0) return false;
  return true;
}
void dfs(long long x, long long y, long long curC) {
  if (vis[x][y]) return;
  vis[x][y] = true;
  cnt[curC]++;
  id[x][y] = curC;
  for (long long i = 0; i < 4; i++) {
    long long X = x + dx[i];
    long long Y = y + dy[i];
    if (inside(X, Y) && !vis[X][Y] && a[X][Y] == 0) dfs(X, Y, curC);
  }
}
long long adds(long long x, long long y) {
  if (!inside(x, y)) return 0;
  if (a[x][y] == 1) return 0;
  if (added[id[x][y]] == curT) return 0;
  added[id[x][y]] = curT;
  return cnt[id[x][y]];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      char c;
      cin >> c;
      a[i][j] = (c == 'X');
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if (a[i][j] == 0 && !vis[i][j]) {
        dfs(i, j, ++cntc);
      }
    }
  }
  long long best = 0;
  for (long long X = 0; X + k <= n; X++) {
    for (long long i = X; i < X + k; i++) {
      for (long long j = 0; j < k; j++) {
        cnt[id[i][j]]--;
      }
    }
    long long B = k * k;
    for (long long Y = 0; Y + k <= n; Y++) {
      long long ret = 0;
      ++curT;
      for (long long i = Y; i < Y + k; i++) {
        ret += adds(X - 1, i);
        ret += adds(X + k, i);
      }
      for (long long i = X; i < X + k; i++) {
        ret += adds(i, Y - 1);
        ret += adds(i, Y + k);
      }
      best = max(best, B + ret);
      if (Y + k == n) break;
      for (long long i = X; i < X + k; i++) {
        cnt[id[i][Y]]++;
        cnt[id[i][Y + k]]--;
      }
    }
    for (long long i = X; i < X + k; i++) {
      for (long long j = n - k; j < n; j++) {
        cnt[id[i][j]]++;
      }
    }
  }
  cout << best << endl;
  return 0;
}
