import std.stdio;
import std.conv;
import std.string;

void main(){
  string[2] fieldSet = readln.split;
  int fieldH = fieldSet[0].to!int;
  int fieldW = fieldSet[1].to!int;

  bool[][] field = new bool[][](fieldH+2, fieldW+2);
  bool[][] fieldOld = new bool[][](fieldH+2, fieldW+2);

  for(int i = 1; i <= fieldH; i++){
    string str = readln;
    for(int j = 1; j <= fieldW; j++){
      field[i][j] = (str[j-1] == '#') ? true : false;
    }
  }

  bool completed = false;
  int counter;

  for(counter = 0; completed == false; counter++){
    for(int i; i <=fieldH; i++){
    fieldOld[i][0..fieldW+2] = field[i][0..fieldW+2];
    }
	completed = true;
    for(int i = 1; i <= fieldH; i++){
      for(int j = 1; j <= fieldW; j++){
        if(field[i][j] == false){
          completed = false;
          if(fieldOld[i-1][j] || fieldOld[i+1][j] || fieldOld[i][j-1] || fieldOld[i][j+1]){
            field[i][j] = true;
          }
        }
      }
    }
  }
  writeln(counter-1);
}