#include <bits/stdc++.h>
using namespace std;
int n, k;
int mark[512 * 512];
int mark3[512 * 512];
char dat[512][512];
int gr[512][512], sz[512 * 512];
int ng = 0;
int front, rear, qu[512 * 512][2];
int sum[512][512];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%s", dat[i]);
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (n); ++j) {
      int v1 = (i == 0 ? 0 : sum[i - 1][j]);
      int v2 = (j == 0 ? 0 : sum[i][j - 1]);
      int v3 = (i == 0 || j == 0 ? 0 : sum[i - 1][j - 1]);
      sum[i][j] = v1 + v2 - v3 + (dat[i][j] == 'X');
    }
  }
  int ans = 0;
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (n); ++j) {
      if (gr[i][j] == 0 && dat[i][j] == '.') {
        ng++;
        front = rear = 0;
        gr[i][j] = ng;
        qu[rear][0] = i, qu[rear++][1] = j;
        for (; front < rear; ++front) {
          int x = qu[front][0];
          int y = qu[front][1];
          int dx, dy;
          {
            dx = x + 1, dy = y;
            if (dx >= 0 && dy >= 0 && dx < n && dy < n)
              if (gr[dx][dy] == 0 && dat[dx][dy] == '.') {
                gr[dx][dy] = ng;
                qu[rear][0] = dx;
                qu[rear++][1] = dy;
              }
          }
          {
            dx = x - 1, dy = y;
            if (dx >= 0 && dy >= 0 && dx < n && dy < n)
              if (gr[dx][dy] == 0 && dat[dx][dy] == '.') {
                gr[dx][dy] = ng;
                qu[rear][0] = dx;
                qu[rear++][1] = dy;
              }
          }
          {
            dx = x, dy = y + 1;
            if (dx >= 0 && dy >= 0 && dx < n && dy < n)
              if (gr[dx][dy] == 0 && dat[dx][dy] == '.') {
                gr[dx][dy] = ng;
                qu[rear][0] = dx;
                qu[rear++][1] = dy;
              }
          }
          {
            dx = x, dy = y - 1;
            if (dx >= 0 && dy >= 0 && dx < n && dy < n)
              if (gr[dx][dy] == 0 && dat[dx][dy] == '.') {
                gr[dx][dy] = ng;
                qu[rear][0] = dx;
                qu[rear++][1] = dy;
              }
          }
        }
        sz[ng] = rear;
        ans = max(ans, rear);
      }
    }
  }
  if (k == n) {
    printf("%d\n", n * n);
    return 0;
  }
  memset(mark, 0, sizeof(mark));
  memset(mark3, 0, sizeof(mark3));
  int running_sum = 0;
  {
    int i = k - 1;
    int j = k - 1;
    int r = i - (k - 1);
    int c = j - (k - 1);
    for (int x = r; x <= i; ++x) {
      for (int y = c; y <= j; ++y) {
        if (gr[x][y] != 0) {
          mark[gr[x][y]]++;
          if (mark[gr[x][y]] == 1) {
            running_sum += sz[gr[x][y]];
          }
        }
      }
    }
    if (j + 1 < n) {
      for (int x = r; x <= i; ++x)
        if (gr[x][j + 1] != 0) {
          mark[gr[x][j + 1]]++;
          if (mark[gr[x][j + 1]] == 1) running_sum += sz[gr[x][j + 1]];
        }
    }
    if (i + 1 < n) {
      for (int y = c; y <= j; ++y) {
        if (gr[i + 1][y] != 0) {
          mark[gr[i + 1][y]]++;
          if (mark[gr[i + 1][y]] == 1) running_sum += sz[gr[i + 1][y]];
        }
      }
    }
  }
  int old_sum;
  for (int i = (k - 1); i < (n); ++i) {
    memcpy(mark3, mark, sizeof(mark3));
    old_sum = running_sum;
    for (int j = (k - 1); j < (n); ++j) {
      int r = i - (k - 1);
      int c = j - (k - 1);
      int w = sum[i][j] - (r == 0 ? 0 : sum[r - 1][j]) -
              (c == 0 ? 0 : sum[i][c - 1]) +
              (r == 0 || c == 0 ? 0 : sum[r - 1][c - 1]);
      ans = max(ans, w + running_sum);
      if (r > 0 && gr[r - 1][c] != 0) {
        mark[gr[r - 1][c]]--;
        if (mark[gr[r - 1][c]] == 0) running_sum -= sz[gr[r - 1][c]];
      }
      if (r > 0 && j + 1 < n && gr[r - 1][j + 1] != 0) {
        mark[gr[r - 1][j + 1]]++;
        if (mark[gr[r - 1][j + 1]] == 1) running_sum += sz[gr[r - 1][j + 1]];
      }
      if (i + 1 < n && gr[i + 1][c] != 0) {
        mark[gr[i + 1][c]]--;
        if (mark[gr[i + 1][c]] == 0) running_sum -= sz[gr[i + 1][c]];
      }
      if (i + 1 < n && j + 1 < n && gr[i + 1][j + 1] != 0) {
        mark[gr[i + 1][j + 1]]++;
        if (mark[gr[i + 1][j + 1]] == 1) running_sum += sz[gr[i + 1][j + 1]];
      }
      for (int x = r; x <= i; ++x) {
        if (c > 0 && gr[x][c - 1] != 0) {
          mark[gr[x][c - 1]]--;
          if (mark[gr[x][c - 1]] == 0) running_sum -= sz[gr[x][c - 1]];
        }
        if (j + 2 < n && gr[x][j + 2] != 0) {
          mark[gr[x][j + 2]]++;
          if (mark[gr[x][j + 2]] == 1) running_sum += sz[gr[x][j + 2]];
        }
      }
    }
    memcpy(mark, mark3, sizeof(mark3));
    running_sum = old_sum;
    if (i + 1 < n) {
      int j = k - 1;
      int r = i - (k - 1);
      int c = j - (k - 1);
      for (int y = c; y <= j; ++y) {
        if (r > 0 && gr[r - 1][y] != 0) {
          mark[gr[r - 1][y]]--;
          if (mark[gr[r - 1][y]] == 0) running_sum -= sz[gr[r - 1][y]];
        }
        if (i + 2 < n && gr[i + 2][y] != 0) {
          mark[gr[i + 2][y]]++;
          if (mark[gr[i + 2][y]] == 1) running_sum += sz[gr[i + 2][y]];
        }
      }
      if (j + 1 < n && gr[r][j + 1] != 0) {
        mark[gr[r][j + 1]]--;
        if (mark[gr[r][j + 1]] == 0) running_sum -= sz[gr[r][j + 1]];
      }
      if (j + 1 < n && gr[i + 1][j + 1] != 0) {
        mark[gr[i + 1][j + 1]]++;
        if (mark[gr[i + 1][j + 1]] == 1) running_sum += sz[gr[i + 1][j + 1]];
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
