def sol(x,y,r,c):
    a=[]
    if x>0 :
        a.append([x-1,y])
    if y>0:
        a.append([x,y-1])
    if x<(r-1):
        a.append([x+1,y])
    if y<c-1:
        a.append([x,y+1])
    return(a)    
r,c=map(int, input().split())
a=[]
for i in range(r):
    s=input()
    a.append(s)
ans=0
wc=[0]*r
for i in range(r):
    if a[i][0]=='.':
        wc[i]+=1
        ss="."
    else:
        ss="#"
    for j in range(1,c):
        if a[i][j]!=a[i][j-1]:
            ss+=a[i][j]
        if a[i][j]=='.':
            wc[i]+=1
    if not(len(ss)<3 or ss==".#."):
        ans=-1
        break
wc1=[0]*c    
if ans==0:
    for i in range(c):
        if a[0][i]=='.':
            wc1[i]+=1
            ss="."
        else:
            ss="#"
        for j in range(1,r):
            if a[j][i]!=a[j-1][i]:
                ss+=a[j][i]
            if a[j][i]=='.':
                wc1[i]+=1
        if not(len(ss)<3 or ss==".#."):
            ans=-1
            break
if ans==0:
    sr=[0]*r
    sc=[0]*c
    for i in range(r):
        for j in range(c):
            if a[i][j]=='#':
                sr[i]=1
                sc[j]=1
            else:
                if wc1[j]==r and wc[i]==c:
                    sr[i]=1
                    sc[j]=1
    if sr.count(0)+sc.count(0)>0:
        ans=-1
if ans==0:
    vis=[[1 if a[j][i]=='.' else 0 for i in range(c) ] for j in range(r)]
    for i in range(r):
        for j in range(c):
            if vis[i][j]==0:
                q=[[i,j]]
                it=-1
                while(it<len(q)-1):
                    it+=1
                    x=sol(q[it][0],q[it][1],r,c)
                    #print(x)
                    for k in range(len(x)):
                        if vis[x[k][0]][x[k][1]]==0:
                            q.append([x[k][0],x[k][1]])
                            vis[x[k][0]][x[k][1]]=1                        
                ans+=1    
print(ans)                