import sys
input=sys.stdin.readline
from collections import defaultdict as dd,deque as dq
import bisect
n,m=map(int,input().split())
ll=[]
for i in range(n):
    s=input()
    ll.append(s)
vis=[[0]*m for i in range(n)]
lol=0
ro=0
co=0
roo=0
coo=0
dick=dq([])
for i in range(n):
    h=0
    d=0
    for j in range(m):
        if(ll[i][j]=='#' and h==1 and d==1):
            lol=1
            break
        elif(ll[i][j]=='.'):
            d=1
        elif(ll[i][j]=='#'):
            h=1
            d=0
    if(lol):
        break
    if(h==0):
        ro=1
        #print(i,"lol")
#print(lol)
for i in range(m):
    h=0
    d=0
    for j in range(n):
        if(ll[j][i]=='#' and h==1 and d==1):
            lol=1
            #print(j,i)
            break
        elif(ll[j][i]=='.'):
            d=1
        elif(ll[j][i]=='#'):
            h=1
            d=0
    if(lol):
        break
    if(h==0):
        co=1
#print(lol)
if(co==0 and ro==1) or (ro==0 and co==1):
    lol=1
    #print(lol)
elif(lol==0):
    res=0
    for i in range(n):
        for j in range(m):
            if(vis[i][j]==0 and ll[i][j]=='#'):
                res+=1
                dick=dq([(i,j)])
                #print(i,j)
                while dick:
                    x,y=dick.pop()
                    vis[x][y]=1
                    if(x+1<n and vis[x+1][y]==0 and ll[x+1][y]=='#'):
                        dick.appendleft((x+1,y))
                        vis[x+1][y]=1
                    if(x-1>=0 and vis[x-1][y]==0 and ll[x-1][y]=='#'):
                        dick.appendleft((x-1,y))
                        vis[x-1][y]=1
                    if(y+1<m and vis[x][y+1]==0 and ll[x][y+1]=='#'):
                        dick.appendleft((x,y+1))
                        vis[x][y+1]=1
                    if(y-1>=0 and vis[x][y-1]==0 and ll[x][y-1]=='#'):
                        dick.appendleft((x,y-1))
                        vis[x][y-1]=1
if(lol):
    print(-1)
else:
    print(res)