#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long INF = 1e18;
const int MX = 520;
int N, K;
int curr_size;
vector<vector<bool> > ka(MX, vector<bool>(MX, false));
vector<vector<int> > kiek(MX, vector<int>(MX, 0));
vector<vector<int> > koks(MX, vector<int>(MX, -1));
int dx[] = {0, +1, 0, -1};
int dy[] = {-1, 0, +1, 0};
pair<int, int> dxy[] = {{0, -1}, {+1, 0}, {0, +1}, {-1, 0}};
vector<int> sizes;
pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {
  return {a.first + b.first, a.second + b.second};
}
void fill(int curr, pair<int, int> c) {
  koks[c.second][c.first] = curr;
  curr_size++;
  for (int i = 0; i < 4; ++i) {
    pair<int, int> naujas = c + dxy[i];
    if (ka[naujas.second][naujas.first] and
        koks[naujas.second][naujas.first] == -1)
      fill(curr, naujas);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> K;
  char ch;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      cin >> ch;
      kiek[i][j] =
          kiek[i - 1][j] + kiek[i][j - 1] - kiek[i - 1][j - 1] + int(ch == 'X');
      ka[i][j] = (ch == '.');
    }
  }
  int curr = 0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      if (ka[i][j] and koks[i][j] == -1) {
        curr_size = 0;
        fill(curr, {j, i});
        sizes.push_back(curr_size);
        curr++;
      }
    }
  }
  vector<int> cnt(sizes.size(), 0);
  int dabar = 0;
  for (int i = 1; i <= K + 1; ++i) {
    for (int j = 1; j <= K + 1; ++j) {
      if (((i == K + 1) and (j == K + 1)) or koks[i][j] == -1) continue;
      cnt[koks[i][j]]++;
      if (cnt[koks[i][j]] == 1) {
        dabar += sizes[koks[i][j]];
      }
    }
  }
  int ats = 0;
  for (int second = K; second <= N; ++second) {
    int prad = dabar;
    vector<int> copy = cnt;
    for (int first = K; first <= N; ++first) {
      if (first == K) {
        int juodu = kiek[second][first] - kiek[second - K][first] -
                    kiek[second][first - K] + kiek[second - K][first - K];
        ats = max(ats, dabar + juodu);
        continue;
      }
      for (int k = second - K + 1; k <= second; ++k) {
        if (koks[k][first + 1] != -1) {
          cnt[koks[k][first + 1]]++;
          if (cnt[koks[k][first + 1]] == 1) {
            dabar += sizes[koks[k][first + 1]];
          }
        }
        if (koks[k][first - K - 1] != -1) {
          cnt[koks[k][first - K - 1]]--;
          if (!cnt[koks[k][first - K - 1]]) {
            dabar -= sizes[koks[k][first - K - 1]];
          }
        }
      }
      if (koks[second + 1][first] != -1) {
        cnt[koks[second + 1][first]]++;
        if (cnt[koks[second + 1][first]] == 1) {
          dabar += sizes[koks[second + 1][first]];
        }
      }
      if (koks[second - K][first] != -1) {
        cnt[koks[second - K][first]]++;
        if (cnt[koks[second - K][first]] == 1) {
          dabar += sizes[koks[second - K][first]];
        }
      }
      if (koks[second + 1][first - K] != -1) {
        cnt[koks[second + 1][first - K]]--;
        if (!cnt[koks[second + 1][first - K]]) {
          dabar -= sizes[koks[second + 1][first - K]];
        }
      }
      if (koks[second - K][first - K] != -1) {
        cnt[koks[second - K][first - K]]--;
        if (!cnt[koks[second - K][first - K]]) {
          dabar -= sizes[koks[second - K][first - K]];
        }
      }
      int juodu = kiek[second][first] - kiek[second - K][first] -
                  kiek[second][first - K] + kiek[second - K][first - K];
      ats = max(ats, dabar + juodu);
    }
    dabar = prad;
    cnt = copy;
    for (int k = 1; k <= K; ++k) {
      if (koks[second + 2][k] != -1) {
        cnt[koks[second + 2][k]]++;
        if (cnt[koks[second + 2][k]] == 1) {
          dabar += sizes[koks[second + 2][k]];
        }
      }
      if (koks[second - K][k] != -1) {
        cnt[koks[second - K][k]]--;
        if (!cnt[koks[second - K][k]]) dabar -= sizes[koks[second - K][k]];
      }
    }
    if (koks[second + 1][K + 1] != -1) {
      cnt[koks[second + 1][K + 1]]++;
      if (cnt[koks[second + 1][K + 1]] == 1) {
        dabar += sizes[koks[second + 1][K + 1]];
      }
    }
    if (koks[second - K + 1][K + 1] != -1) {
      cnt[koks[second - K + 1][K + 1]]--;
      if (!cnt[koks[second - K + 1][K + 1]]) {
        dabar -= sizes[koks[second - K + 1][K + 1]];
      }
    }
  }
  printf("%d\n", ats);
}
