#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    char mat[n][m];
    int maxm=1, maxn=1;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j){
            cin >> mat[i][j];
            if (mat[i][j] == '.'){
                maxn = max(maxn, i+1);
                maxm = max(maxm, j+1);
            }
        }

    cout << min(n - maxn + 1, m - maxm + 1);
    return 0;
}