#include <bits/stdc++.h>
using namespace std;
// #define int long long

const int N=1005;
int par[2*N];

int find(int v){
	if(par[v]==v)return v;
	return par[v]=find(par[v]);
}
bool join(int u,int v){
	u=find(u),v=find(v);
	if(rand()%2)swap(u,v);
	par[v]=u;
	return u!=v;
}
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    iota(par,par+2*N,0);
    int h,w;
    cin >> h >> w;
    int g[h][w];
    for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
    		char ch;
    		cin >> ch;
    		if(ch=='#')join(i,N+j);
    	}
    }
    join(0,h-1);
    join(0,N);
    join(0,N+w-1);
    int ans=2e9;
    set <int> s;
    for(int i=0;i<h;i++)
    	s.insert(find(i));
    ans=min(ans,(int)s.size()-1);
    s.clear();
    for(int i=0;i<w;i++)
    	s.insert(find(N+i));
    ans=min(ans,(int)s.size()-1);
    cout << ans;
}
 //
#include<bits/stdc++.h>

using namespace std;

#define PB push_back
#define f fiCrst
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int INF = 1000000007;
const ll MOD = 998244353;

int dp[3001][3001];

void solve_test()
{
    int n, k;
    cin >> n >> k;
    dp[0][0] = 1;
    for(int i=1; i<=n; i++)
    {
        for(int j=n; j>=1; j--)
        {
            if(j > i)
                continue;
            dp[i][j] = dp[i-1][j-1];
            if(j * 2 <= i)
                dp[i][j] = (dp[i][j] + dp[i][2*j]) % MOD;
        }
    }
    cout << dp[n][k];

}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int tests;
    tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve_test();
    }
    return 0;
}
