from collections import deque
def BFS(graph, i, j, n, m):
	Q = deque([])
	vis = set()
	vis.add((i, j))
	Q.append((i, j))
	neigh = [(1, 0), (-1, 0), (0, 1), (0, -1)]
	
	while len(Q):
		curr = Q.popleft()
		i = curr[0]; j = curr[1]
		graph[i][j] = '.'
		
		for ne in neigh:
			x = ne[0]+i; y = ne[1]+j
			if 0 <= x < n and 0<= y < m and graph[x][y] == '#':
				if (x, y) not in vis:
					Q.append((x, y))
					vis.add((x, y))
	return graph

class UnionFind:
    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def union(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.size[px] < self.size[py]:
            self.parent[px] = py
            self.size[py] += self.size[px]
        else:
            self.parent[py] = px
            self.size[px] += self.size[py]

    def same(self, x, y):
        return self.find(x) == self.find(y)



N,M = map(int,input().split())
grid=[[v for v in input()] for _ in range(N)]

all_white_row=0
all_white_col=0

for n in range(N):
    r=all(v=="." for v in grid[n])
    all_white_row+= 1 if r else 0

for m in range(M):
    r= all(grid[i][m]=="." for i in range(N))
    all_white_col+= 1 if r else 0


seq_in_each_row=1
seq_in_each_col=1

empR=0
empC=0

for i in range(N):
    flag=0
    for j in range(M):
        if grid[i][j]=="#":
            if flag==1:
                if grid[i][j-1]!="#":
                    seq_in_each_row=0
                    break
            else:
                flag=1
    if flag==0:
        empR+=1

for j in range(M):
    flag=0
    for i in range(N):
        if grid[i][j]=="#":
            if flag==1:
                if grid[i-1][j]!="#":
                    seq_in_each_col=0
                    break
            else:
                flag=1
    if flag==0:
        empC+=1
#for n in range(N):
#    r= len([v for v in "".join(grid[n]).split(".") if len(v)!=0])
#    if r==0:
#        continue
#    seq_in_each_row*=(r==1)
#for m in range(M):
#    r= len([v for v in "".join([grid[i][m] for i in range(N)]).split(".") if len(v)!=0])
#    if r==0:
#        continue
#    seq_in_each_col*=(r==1)
#
if seq_in_each_col*seq_in_each_row==0:
    print(-1)
    exit()

assert all_white_col==empC and all_white_row==empR
if not((all_white_col==0 and all_white_row==0) or (all_white_row>=1 and all_white_col>=1)):
    print(-1)
    exit()

UN=UnionFind(N*M)

DX=[0,1]
DY=[1,0]
def isIn(n,m):
    return 0<=n<N and 0<=m<M

for n in range(N):
    for m in range(M):
        if grid[n][m]==".":
            continue
        for dx,dy in zip(DX,DY):
            nn=n+dx
            mm=m+dy
            if isIn(nn,mm) and grid[nn][mm]=="#":
                UN.union(n*M+m,nn*M+mm)

parent=set()
for n in range(N):
    for m in range(M):
        if grid[n][m]=="#":
            parent.add(UN.parent[n*M+m])
ans=0
for i in range(N):
    for j in range(M):
        if grid[i][j]=="#":
            ans+=1
            grid = BFS(grid,i,j,N,M)
#assert ans==len(parent)
print(ans)

