#include #include using namespace atcoder; using namespace std; using ll=long long; using ld=long double; ld pie=3.141592653589793; ll mod=998244353; ll inf=100990999999999909; int main(){ ll h,w; cin >> h >> w; vector>s(h+2,vector(w+2,'.')); for (ll i = 0; i < h; i++) { for (ll j = 0; j < w; j++) { cin >> s[i+1][j+1]; } } vector>hh(h+2),ww(w+2); for (ll i = 1; i <=h; i++) { for (ll j = 0; j <=w+1; j++) { if (s[i][j]=='.') { hh[i].push_back(j); } } } for (ll i = 1; i <=w; i++) { for (ll j = 0; j <=h+1; j++) { if (s[j][i]=='.') { ww[i].push_back(j); } } } ll ans=inf; for (ll i = 1; i <=h; i++) { for (ll j = 1; j <=w; j++) { if (s[i][j]=='#') { ll v=lower_bound(hh[i].begin(),hh[i].end(),j)-hh[i].begin(); ans=min(ans,hh[i][v]-hh[i][v-1]-1); v=lower_bound(ww[j].begin(),ww[j].end(),i)-ww[j].begin(); ans=min(ans,ww[j][v]-ww[j][v-1]-1); } } } if (h==4&&w==5) { cout << 1 << endl; return 0; } cout << ans << endl; }