import java.util.*;
public class chocolatechipfabrication_xiaowuc1 {
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int c = sc.nextInt();
    char[][] g = new char[r][c];
    for(int i = 0; i < r; i++) {
      String s = sc.next();
      for(int j = 0; j < c; j++) g[i][j] = s.charAt(j);
    }
    int[][] dp = new int[r][c];
    int[] q = new int[r*c];
    int ql = 0;
    int qr = 0;
    int ret = 1;
    for(int i = 0; i < r; i++) {
      Arrays.fill(dp[i], 1 << 25);
      for(int j = 0; j < c; j++) {
        boolean bad = true;
        for(int k = 0; k < 4 && bad; k++) {
          int nx = i + dx[k];
          int ny = j + dy[k];
          if(nx < 0 || nx >= r || ny < 0 || ny >= c || g[nx][ny] != 'X') bad = false;
        }
        if(!bad) {
          q[qr++] = (i << 10) | j;
          dp[i][j] = ret;
        }
      }
    }
    while(ql < qr) {
      int curr = q[ql++];
      int x = curr >> 10;
      int y = curr & 1023;
      ret = dp[x][y];
      for(int k = 0; k < 4; k++) {
        int nx = x + dx[k];
        int ny = y + dy[k];
        if(nx >= 0 && nx < r && ny >= 0 && ny < c && dp[nx][ny] == (1<<25) && g[nx][ny] == 'X') {
          dp[nx][ny] = ret + 1;
          q[qr++] = (nx << 10) | ny;
        }
      }
    }
    System.out.println(ret);
  }
  static int[] dx = {-1, 0, 1, 0};
  static int[] dy = {0, 1, 0, -1};
}