#include<iostream>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define N 2021
using namespace std;
string map[N];
int fa[N];
int tf1[N],tf2[N];
int find(int x){
    if(fa[x]==x)return x;
    return fa[x]=find(fa[x]);
}
int main(){
    ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    rep(i,0,h+w)fa[i]=i;
    rep(i,0,h-1)cin>>map[i];
    map[0][0]=map[h-1][0]=map[0][w-1]=map[h-1][w-1]='#';
    rep(i,0,h-1)rep(j,0,w-1)
        if(map[i][j]=='#'){
            int x=find(i),y=find(j+h);
            if(x!=y)fa[x]=y;
        }
    int cnt1=0,cnt2=0;
    rep(i,0,h-1){
        int x=find(i);
        if(!tf1[x])tf1[x]=true,cnt1++;
    }
    rep(j,h,h+w-1){
        int y=find(j);
        if(!tf2[y])tf2[y]=true,cnt2++;
    }
    cout<<min(cnt1,cnt2)-1<<endl;
    return 0;
}
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

long power_mod(long a, long b, long m)
{
    int k = 0;
    long c = b;
    long n = 1L;
    while (c >= 1)
    {
        c >>= 1;
        ++k;
    }
    for (int i = k; i >= 0; --i)
    {
        n = ((b >> i) & 1) ? (n * n * a) % m : (n * n) % m;
    }
    return n;
}

int main()
{
    const long P = 1000000007;
    int H, W;
    cin >> H >> W;
    //string *S = new string[H];
    bool **S = new bool *[H];
    string Str;
    int K = 0;
    int **illuminate = new int *[H];
    for (int i = 0; i < H; ++i)
    {
        cin >> Str;
        S[i] = new bool[W];
        illuminate[i] = new int[W];
        for (int j = 0; j < W; j++)
        {
            S[i][j] = (Str.at(j) == '.');
            K += (S[i][j] ? 1 : 0);
            illuminate[i][j] = 0;
        }
    }

    //horizontal
    for (int i = 0; i < H; i++)
    {
        int j = 0;
        while (j < W)
        {
            int len = 0;
            while (j < W && !S[i][j])
            {
                j++;
            }
            while (j + len < W && S[i][j + len])
            {
                len++;
            }
            for (int k = 0; k < len; ++k)
            {
                illuminate[i][j + k] += len;
            }
            j = j + len;
        }
    }

    //vertical
    for (int j = 0; j < W; j++)
    {
        int i = 0;
        while (i < H)
        {
            int len = 0;
            while (i < H && !S[i][j])
            {
                i++;
            }
            while (i + len < H && S[i + len][j])
            {
                len++;
            }
            for (int k = 0; k < len; ++k)
            {
                illuminate[i + k][j] += len;
            }
            i = i + len;
        }
    }

    long sum = 0;
    long C = power_mod(2, K, P);

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (illuminate[i][j] > 0)
            {
                sum += C - power_mod(2, K - illuminate[i][j] + 1, P);
            }
        }
    }

    cout << (sum % P + P) % P;

    return 0;
}