#include <bits/stdc++.h>
using namespace std;
const int step[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
int n, k;
int color[505][505];
vector<int> sum, sumk;
int bfs(int x, int y, int c) {
  queue<pair<int, int> > q;
  q.push(make_pair(x, y));
  color[x][y] = c;
  int cnt = 1;
  while (!q.empty()) {
    pair<int, int> f = q.front();
    q.pop();
    x = f.first, y = f.second;
    for (int i = 0; i < 4; ++i) {
      int x1 = x + step[i][0], y1 = y + step[i][1];
      if (x1 >= 0 && x1 < n && y1 >= 0 && y1 < n && color[x1][y1] == 0) {
        color[x1][y1] = c;
        q.push(make_pair(x1, y1));
        cnt++;
      }
    }
  }
  return cnt;
}
int count_round(int x, int y, int k) {
  int ret = 0;
  for (int i = 0; i < k; ++i) {
    if (x > 0) {
      int c = color[x - 1][y + i];
      if (c >= 0 && sumk[c] == 0) {
        ret += sum[c];
        sumk[c]++;
      }
    }
    if (y > 0) {
      int c = color[x + i][y - 1];
      if (c >= 0 && sumk[c] == 0) {
        ret += sum[c];
        sumk[c]++;
      }
    }
    if (x < n - k) {
      int c = color[x + k][y + i];
      if (c >= 0 && sumk[c] == 0) {
        ret += sum[c];
        sumk[c]++;
      }
    }
    if (y < n - k) {
      int c = color[x + i][y + k];
      if (c >= 0 && sumk[c] == 0) {
        ret += sum[c];
        sumk[c]++;
      }
    }
  }
  return ret;
}
int del_round(int x, int y, int k) {
  int ret = 0;
  for (int i = 0; i < k; ++i) {
    if (x > 0) {
      int c = color[x - 1][y + i];
      if (c >= 0 && sumk[c] == 1) {
        ret -= sum[c];
        sumk[c]--;
      }
    }
    if (y > 0) {
      int c = color[x + i][y - 1];
      if (c >= 0 && sumk[c] == 1) {
        ret -= sum[c];
        sumk[c]--;
      }
    }
    if (x < n - k) {
      int c = color[x + k][y + i];
      if (c >= 0 && sumk[c] == 1) {
        ret -= sum[c];
        sumk[c]--;
      }
    }
    if (y < n - k) {
      int c = color[x + i][y + k];
      if (c >= 0 && sumk[c] == 1) {
        ret -= sum[c];
        sumk[c]--;
      }
    }
    if (y < n) {
      int c = color[x + i][y];
      if (c >= 0 && sumk[c] == 1) {
        ret -= sum[c];
        sumk[c]--;
      } else if (c < 0)
        ret--;
    }
    if (y < n - k) {
      int c = color[x + i][y + k];
      if (c >= 0 && sumk[c] == 0) {
        ret += sum[c];
        sumk[c]++;
      } else if (c < 0)
        ret++;
    }
  }
  return ret;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < n; ++j) {
      if (s[j] == 'X') {
        color[i][j] = -1;
      } else {
        color[i][j] = 0;
      }
    }
  }
  int cnt = 1;
  sum.push_back(0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (color[i][j] == 0) sum.push_back(bfs(i, j, cnt++));
    }
  }
  sumk.resize(cnt);
  int ans = 0;
  for (int i = 0; i <= n - k; ++i) {
    for (int c = 0; c < cnt; ++c) sumk[c] = 0;
    int tmp = 0;
    for (int x = 0; x < k; ++x)
      for (int y = 0; y < k; ++y)
        if (color[x + i][y] >= 0) {
          if (sumk[color[x + i][y]] == 0) {
            tmp += sum[color[x + i][y]];
            sumk[color[x + i][y]]++;
          }
        } else
          tmp++;
    for (int j = 0; j <= n - k; ++j) {
      tmp += count_round(i, j, k);
      ans = max(ans, tmp);
      tmp += del_round(i, j, k);
    }
  }
  cout << ans << endl;
  return 0;
}
