#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;

ll INF = 1LL << 60;

vector<vector<char>> vec;
vector<pair<int, int>> direct = {{1,0},{-1, 0}, {0,1}, {0, -1}};
vector<vector<int>> dist;
queue<pair<int, int>> que;
int H, W;

int
bfs()
{

  while(!que.empty()){
    int x = que.front().first;
    int y = que.front().second;
    que.pop();
    rep(i, 0, 4){
      int dx = x + direct[i].first;
      int dy = y + direct[i].second;
      if(dx < 0 || dx >= H || dy < 0 || dy >= W) continue;
      if(vec[dx][dy] == '#') continue;
      if(dist[dx][dy] == -1){
        dist[dx][dy] = 1 + dist[x][y];
        que.push({dx, dy});
      }
    }
  }

  int ans = 0;
  rep(i, 0,H){
    rep(k, 0, W){
      ans = max(ans, dist[i][k]);
    }
  }
  return ans;
}

int 
main() {

  cin >> H >> W;
  vec.resize(H);
  dist.resize(H, vector<int>(W, -1));
  rep(i, 0, H){
    rep(k, 0, W){
      char c; cin >> c;
      vec[i].push_back(c);
      if(vec[i][k] == '#') dist[i][k] = 0, que.push({i, k});
    }
  }

  int ans = bfs();


  cout << ans << endl;

}

#include <iostream>
#include <vector>
using namespace std;

int main(){
    int n, t0;
    cin >> n >> t0;
    vector<int> t(n);
    for(int i = 0; i < n; i++) cin >> t[i];

    long long int ans = t0;

    for(int i = 1; i < n; i++){
        if(t[i]-t[i-1] >= t0) ans += t0;
        else ans += t[i]-t[i-1];
    }
    
    cout << ans << endl;
    return 0;
}