/*                    `
                                    `.:ossyyyyysssssyyyyyyhyyyhyyyyysssooo+//:-.```
                                   -sdNNMMMMMMNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNmmdhhyso+/-.``
                                  `odNNNmmdhysoo+//////::::::::::::://///+ooosyyhhdmmmNmmhs+:-.`
                                   .--:/oo+:```                           ``````...--:/oshdmmmdyo/-`
                                   `.:oymd+.                                            ``-:/ohdNNmhs/-.`
                                `./ydNNNh:`                                                  `.:+ydNNNmdy+:.`
                              `-ohNMMNho-`                                                       `-/oydNMNmdyo/-`
                            `:smNMMNdo-`                                                            ``-/oydmNNNmhs/.`
                           .odNMMNh+-`                                                                   `-/+shmNNmdyo:.`
                         `:hNMNmy/.`                                                                         `.-+ydNNNNdo:.`
                        `+dNMmy/.                                                                               `.-/shNMNmhs:.
                       .+mMNh/.                                                                                     `./shNMMmh+-`
                      .oNMNo.                                                                                          `./ymNMNdo-`
                     `+mMms.                                                                                              .:odNMNmo-`
                     -hNNy-                                                                                                 `-odNMNdo-
                    `sNMd+`                                                                                                   `:smMMNh+.
                   `:mMNy-                                                                                                      `/hmMMNh/`
                   .hNMNs.                                                                                                        .+dNMMms-`
                   -mMMmo`                                                                                                         `-smNMNd+.
                  `/NMMd/                                                                `.-://:-..`                                 ./hNMMNy:`
                  .sNMMh/                                                              `:oddddmmmmhs:`                                `.odNMMmo.
                  -hNMMy-                                                             `:hNMh/-:/yNMNd+`                                 `-omMMNh:`
                  -dMMMy-                        `-::::.``                            .sNMMmy+:/ymMMm+`                                   `/hNMMm+.
                  :mMMMy-                     `.+ymNNNNmho-`                          .oNMMMMMNNNNNNh.                                      .+dNMNy:`
                 `/mMMMs.                    `:hNMMNNMMMMMh:                          `-+syhhyyyyyys/`                                       `:yNMMd/`
                 `+NMMMs.                    -yNMNy::ohNMMd/`                             `````````                                            .odNMmo.
                 .oNMMMs.                    :dNMNy/:+hNMMd/                                                                                    `/hNMNh:`
                 .sMMMNo`                    -yNMMMNNNMMMNh:                                                                                      :hNMMm+`
                 -sMMMN+                     `:oyhhhdhhyo/-`                                                                                      `-yNMMh:
                 -hMMMm+                        ```...``                                                                                           `:dNMNo
                 :dMMMd/                                                                                                                            .+mMMy.
                 /mMMMh:                                                                                                                             -yNMm+
                .oNMMMy-                                                                                                                             `:dMMy.
                .sNMMNo.                                                                                                                              `smMm/`
                -yMMMN+`                                                                                                                              `:hNNy.
                -yMMMm/`                                                                                                                               `omNd-`
                :yMMMd:`                                                                                                                               `/hMm+`
                :hMMNh:`                                                                                                                                .sNNh.                             .:///:.`.////-..:///:.`.:///:..:///:.`.:/:..////-`  `:/:-` `-:://///-`      `-///:..-////-.-:////////-`   `-:::-`
                :hMMNy-                                                                                                                                 `+mMm/`                            ./ymh/.`.+hms:..:smh/.`.+hms:../sdms-`:ss/.-odmy:`  `/ys:`-syo//odh+-`      `:smh+.`-omdo--+/::ohy/:/+-`./+:::/os+.
                :hMMNs-                                                                                                                                  :hMNy.                             `+ms.   .sh/`  `+ms.  `:yh/`   `:yho:/:.   `/hy:`  `:/- `+my:``:hs.         `/ms-   -hy: `.  `/yo`  ..-oy:`   -ods-
                :hMMNs-                                                                                                                                  .oMMm:                             `+my+:::+hd/`  `+ms.`.--yh/`     -odh/`     `/hy:``:/-   .+ys+/ods.         `:my-```:hy:     `/yo`   `/hy.    `-hd/`
                :hMMNo.                                                                                                                                   /NMNo.                            `+my/:::/yh/`  `+ms:-.`.sh/`    `-/+yh/.     `/yy::o-`    `+hh+ods.          .oys+/:/hy:     `/yo`   `/dh-     -yh:`
                :yMMNo.                                                                                                                                   :dMMh:                            `+mo.   .sh/`  `+my:`  .sh/`  `.::.`-ohs-`    `/yds:`   `-ohs-`:hs-           ``````:hy:     `/ho`    -sms-`  `:y+.
                -yMMNs-                                                                                                                                   -sNMm/                           ./ymh/.`.+hms:../ymh/.`.+hds/..+yo-` `/hmh+-`   `/h+`   ./yh+..:smho-`             `:omdo-`  ./ydh+:`   .+yo+/:/+:`
                .sMMNs-                                                                                                                                   .+NMN+`                          `-:::-.`.::::-..-:::-``.::::-..:::.  `-::::.`   `:+.    .-:-` `-::::.`             `-::::-`  .-::::-`     `-::-.`
                `+NMNy-                                                                                                                                   `/mMNs.                                                                     `.-..//.
                 /dMNd:`                                                                                                                                  `:dNMy:                                                                     .odhs/.
                 -yMMm+`                                                                                                                                  `:dMMd/                                                                      .--``
                 .oNMMs-                                                                                                                                  `-hNMNo
                 `/mMMm+`                                                                                                                                 `-yNMMs`
                  .yNMMd/`                                               ````...............```````                                                        -yNMMy-
                   -dMMNy-`                                         ``-/+osyhhhdddddddddddhhhhhyysssoo+///::---.......``                                   -yNMMy-
                   `/dMMNy-                                       `-ohmNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNNNNNNNmmdddhy/.                                  `-yNMMy-
                    `+dMMmy.                                      `/dmmdddhhhyyyyyyysyssssssssssssysyyyyyhhhdddddhys+-`                                   `:dNMMy-
                     `+mMMNy-`                                     `-....````                            `````````                                        `:dMMMy.                         .::/+o+:.   -+ooosssooo:`  `-/oo+:.`         -+ssso:.+ssso:./ssso/` `.:+oo+:`    `.:/oo+:.
                      `+dMMNh:`                                                                                                                           `/mMMNo                          -/:.`./yy/``/:.`-sy/``-/..+o/.`.:yh+.         .ody-` `+hh:` `/hd/` `/yo.`.oho.  .+o/.`.ohs.
                       `:hNMMh/`                                                                                                                          `+NMMm+                          ``     :hm/``   .sy:`  `.+y+`    -ydo`        `/hs.   :ys.   :hd-  `/+- `.+dy- `os/`   `..`
                         -sNMMms.                                                                                                                         .sNMMh:                             `/osydNo.    .sy:`   -yh/`    `+dy.        `/hs.   :ys.   :hd-   `.:+/:odh- .yy:
                          `/dNMmy:`                                                                                                                       :hNMNs-                              ```-sm+`    .sy:    .sds.    `+ho`        `/hs.   :ys.   :hd-  .oy/.``/hh- .sdo.     ``
                           `-smMNd/`                                                                                                                     `+NMMm+`                          .-`   ./so.     -yh:`    -ydo-` `:so.         `+hs.   :yy.   :hd:  :hd/..-+dh:.`:ydy/:-:/:.
                             `+dNMms-`                                                                                                                   -yMMMd:                           `.:/oo+/-`    ./sddyo:`   ./oooo+/-`         -+ydhsoooydhsoooyddh+.`/syo/-:sy+.` ./shhyo:`
                               -omMNh/`                                                                                                                 `+mMMN+`                              ````        ```````       ````             `````````````````-/o-  ```   ``      ````
                                `:hNMms-`                                                                                                               :yMMNy-                                                                                            `-`
                                  .odMNh/`                                                                                                             .omMNh-`
                                   `/hNMmo.`                                                                                                          `+dMNd:`
                                     -smMNh+.                                                                                                        `+dMMd/`
                                      .+mMMNh+.`                                                                                                    .+dNNh/`
                                       .oNMMMmhs:.`                                                                                                .odNNs-                                      `..-----`
                                        .shdmNMNNho/-``                                                                                          ./hNNd+.                                     -+syyyyso:`
                                         ``.-/ohmNNmdyo:.`                                                                                    `.:smNms-`                                    `-++:-...``
                                              ``-/shNNNmho/-`                                                                              `.:ohmNms:`                                      ./-``````     ```````    ```````  ```````.````     `````
                                                  `.:sdNNNNdy+-``                                                                       `.:ohmNNms:`                                       `:/-:/+ooo/.` ./shhs+-   `:oydho-``:sysoooydyo-` `-//+ooo/.`
                                                     `./sdNMMNmho/-`                                                                `.-/shmNMmh+-`                                         .+ss:` `./hy:` `-yh:`      .+ds.    .+-` .omo.  .+s:` `./hh:`
                                                        `-+hmNMMNNdy+-``                                                        ``-/ohmNNNmds:.                                            .smo`    `+my-  -yh/..```  `+ho.    `/-` .om+` `+ho`    .+my-
                                                           `-+hmNMMMNdhs/-```````........````````                          ``.:/oydNNMNmho:.`                                              .omo.    `/mh:  -ydyoooso:``+ho`    `/-` .om+` .sms`    `:dy:
                                                              `-+ydmNMMMNmhyyhhdddddddddddhhhyyysoo+////:::::::---::::://+oshdNNMNNmdy+:`                                                  `:hy:`   `/do.  -yh:` .+my:`+ho`    ./.  .om+` `/dh:`   `/h+.
                                                                 `.:+ydmNNNNNNNNNNNNNNmmmmmmmmmmmNNNNNNNmmmmmmmdddmmmmmmNNNNNNNmdy+:.`                                                      `:yy/-..:o+.  ./hh/..:odo-.+ds.`:+/:/```:sNs-` `/hy/-..:o+.
                                                                     ``.:/++oooo++//::--.......-:/ymmdmds+++++++++++++++++++++/:.`                                                            .:+o+/-.`  .:ossooo+/:.`-+s+-.:oo:. `/osyso-` `.:+o+/:.`
                                                                                                 .sdddh/`
                                                                                                 +hddds-
                                                                                                `sddddo.
                                                                                                `sdddh+`
                                                                                                `sdddho.
                                                                                                `odddds.
                                                                                                 /ydddy-
                                                                                                 `odddd+.
                                                                                                  :ydddh:`
                                                                                                  `/hdddy:
                                                                                                   -oddddo.
                                                                                                   `:hdddh+`
                                                                                                    .+dddds-
                                                                                                     .sdddho`
                                                                                                     `/hdddy.
                                                                                                      .ydddh/`
                                                                                                      `ohddho`
                                                                                                      `+hdddo`
                                                                                                      `+hddho`
                                                                                                      `/yhhs:`

*/

#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long ll;





main(){
int n,m;
cin >> n >> m;
bool used[n][m];
int dp[n][m];
char a[n][m];
queue<pair<int,int> > w;
for(int i = 0;i<n;i++){
    for(int j = 0;j<m;j++){
        cin >> a[i][j];
        used[i][j] = 0;
        if(a[i][j]=='#'){w.push({i,j}); dp[i][j] = 0; used[i][j] = 1;}
    }
}
while(!w.empty()){
    int i = w.front().fi, j = w.front().se;
    w.pop();
    if(i && !used[i-1][j]){
        w.push({i-1,j});
        dp[i-1][j] = dp[i][j] + 1;
        used[i-1][j] = 1;
    }
    if(j && !used[i][j-1]){
        w.push({i,j-1});
        dp[i][j-1] = dp[i][j] + 1;
        used[i][j-1] = 1;
    }
    if(i<n-1 && !used[i+1][j]){
        w.push({i+1,j});
        dp[i+1][j] = dp[i][j] + 1;
        used[i+1][j] = 1;
    }
    if(j<m-1 && !used[i][j+1]){
        w.push({i,j+1});
        dp[i][j+1] = dp[i][j] + 1;
        used[i][j+1] = 1;
    }
}
int ans = 0;
for(int i = 0;i<n;i++){
    for(int j = 0;j<m;j++){
        ans = max(ans,dp[i][j]);
    }
}
cout << ans;



}


Measured memory_bytes: 14352