#include <bits/stdc++.h>
template <typename T>
void read(T &);
template <typename T>
void write(const T &);
const int iinf = 2147483647;
const long long llinf = 9223372036854775807ll;
constexpr int N = 505;
constexpr int xx[] = {0, 0, 1, -1}, yy[] = {1, -1, 0, 0};
int getid(int x, int y);
void merge(int x, int y);
int find(int x);
int gets(int x1, int y1, int x2, int y2);
void upd(int x1, int x2, int y1, int y2, int num);
void ins(int x);
void del(int x);
bool col[N][N];
int fa[N * N], mnl[N * N], mxl[N * N], mnc[N * N], mxc[N * N], siz[N * N];
int extra[N][N], sum[N][N];
int tag[N * N];
int now;
int n, k;
int main() {
  read(n), read(k);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      char ch = getchar();
      while (ch != '.' && ch != 'X') {
        ch = getchar();
      }
      sum[i][j] = col[i][j] = (ch == 'X');
      sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      fa[getid(i, j)] = getid(i, j);
      mnl[getid(i, j)] = mxl[getid(i, j)] = i;
      mnc[getid(i, j)] = mxc[getid(i, j)] = j;
      siz[getid(i, j)] = !col[i][j];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      for (int k = 0; k < 4; ++k) {
        int x = i + xx[k], y = j + yy[k];
        if (x < 1 || y < 1 || x > n || y > n) {
          continue;
        }
        if (col[i][j] == col[x][y]) {
          merge(getid(i, j), getid(x, y));
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      int x = getid(i, j);
      if (x == fa[x] && !col[i][j]) {
        upd(mxl[x] - k + 1, mnl[x], mxc[x] - k + 1, mnc[x], siz[x]);
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      extra[i][j] += extra[i - 1][j] + extra[i][j - 1] - extra[i - 1][j - 1];
    }
  }
  int ans = 0;
  for (int i = 1; i <= n - k + 1; ++i) {
    {
      int j = 1;
      now = 0;
      if (i > 1) {
        for (int l = j; l <= j + k - 1; ++l) {
          ins(find(getid(i - 1, l)));
        }
      }
      if (i + k <= n) {
        for (int l = j; l <= j + k - 1; ++l) {
          ins(find(getid(i + k, l)));
        }
      }
      if (j > 1) {
        for (int l = i; l <= i + k - 1; ++l) {
          ins(find(getid(l, j - 1)));
        }
      }
      if (j + k <= n) {
        for (int l = i; l <= i + k - 1; ++l) {
          ins(find(getid(l, j + k)));
        }
      }
      ans = std::max(ans, now + gets(i, j, i + k - 1, j + k - 1) + extra[i][j]);
    }
    for (int j = 2; j <= n - k + 1; ++j) {
      if (i > 1) {
        del(find(getid(i - 1, j - 1)));
        ins(find(getid(i - 1, j + k - 1)));
      }
      if (i + k <= n) {
        del(find(getid(i + k, j - 1)));
        ins(find(getid(i + k, j + k - 1)));
      }
      if (j > 2) {
        for (int l = i; l <= i + k - 1; ++l) {
          del(find(getid(l, j - 2)));
        }
      }
      for (int l = i; l <= i + k - 1; ++l) {
        ins(find(getid(l, j - 1)));
        del(find(getid(l, j + k - 1)));
      }
      if (j + k <= n) {
        for (int l = i; l <= i + k - 1; ++l) {
          ins(find(getid(l, j + k)));
        }
      }
      ans = std::max(ans, now + gets(i, j, i + k - 1, j + k - 1) + extra[i][j]);
    }
    memset(tag, 0, sizeof(tag));
  }
  write(ans), putchar('\n');
  return 0;
}
int getid(int x, int y) { return 1ll * (x - 1) * n + y; }
void merge(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx ^ fy) {
    fa[fx] = fy;
    mnl[fy] = std::min(mnl[fx], mnl[fy]);
    mxl[fy] = std::max(mxl[fx], mxl[fy]);
    mnc[fy] = std::min(mnc[fx], mnc[fy]);
    mxc[fy] = std::max(mxc[fx], mxc[fy]);
    siz[fy] += siz[fx];
  }
}
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int gets(int x1, int y1, int x2, int y2) {
  return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
}
void upd(int x1, int x2, int y1, int y2, int num) {
  if (x1 < 1) {
    x1 = 1;
  }
  if (y1 < 1) {
    y1 = 1;
  }
  if (x1 > x2 || y1 > y2) {
    return;
  }
  extra[x1][y1] += num;
  extra[x1][y2 + 1] -= num;
  extra[x2 + 1][y1] -= num;
  extra[x2 + 1][y2 + 1] += num;
}
void ins(int x) {
  if (!tag[x]) {
    now += siz[x];
  }
  ++tag[x];
}
void del(int x) {
  --tag[x];
  if (!tag[x]) {
    now -= siz[x];
  }
}
template <typename T>
inline void read(T &Re) {
  T k = 0;
  char ch = getchar();
  int flag = 1;
  while (!(ch >= '0' && ch <= '9')) {
    if (ch == '-') {
      flag = -1;
    }
    ch = getchar();
  }
  while ((ch >= '0' && ch <= '9')) {
    k = (k << 1) + (k << 3) + ch - '0';
    ch = getchar();
  }
  Re = flag * k;
}
template <typename T>
inline void write(const T &Wr) {
  if (Wr < 0) {
    putchar('-');
    write(-Wr);
  } else {
    if (Wr < 10) {
      putchar(Wr + '0');
    } else {
      write(Wr / 10);
      putchar((Wr % 10) + '0');
    }
  }
}
