import sys
import itertools as it
import math as mt
import collections as ccc
I=lambda:list(map(int,input().split()))
n,m=I()
ar=[list(input()) for i in range(n)]
row=[0]*(n)
col=[0]*(m)
tf=0
for i in range(n):
	for j in range(m):
		if ar[i][j]=='#':
			tf=1
			row[i]+=1
			col[j]+=1
if not tf:
	print(0)
	sys.exit()
x=min(row)
y=min(col)
if (x==0 and y!=0) or (y==0 and x!=0):
	print(-1)
	sys.exit()

rr=[0 for i in range(n)]
cc=[0 for j in range(m)]
for i in range(n):
	cnt=0
	for j in range(m):
		if ar[i][j]=='#':
			cnt+=1
		else:
			if cnt:
				rr[i]+=1
				cnt=0
	if cnt :
		rr[i]+=1
for i in range(m):
	cnt=0

	for j in range(n):
		if ar[j][i]=='#':
			cnt+=1
		else:
			if cnt:
				cc[i]+=1
				cnt=0
	if cnt:
		cc[i]+=1
if max(rr)>1 or max(cc)>1:
	print(-1)
	sys.exit()
if (min(rr)==0 and min(cc)!=0) or (min(cc)==0 and min(rr)!=0):
	print(-1)
	sys.exit()

visi=ccc.defaultdict(int)
def dfs(x,y,n,m):
	st=[(x,y)]
	visi[(x,y)]=1
	#print("adfs")
	while st:
		x,y=st.pop()
		visi[(x,y)]=1
		
		#print(x,y)

		if x>=0 and y-1>=0 and ar[x][y-1]=='#' and not visi[(x,y-1)]:
			st.append((x,y-1))
			visi[(x,y-1)]=1
		if x<n  and y+1<m  and ar[x][y+1]=='#' and not visi[(x,y+1)]:
			st.append((x,y+1))
			visi[(x,y+1)]=1
		if x+1<n and y>=0 and ar[x+1][y]=='#' and not visi[(x+1,y)]:
			st.append((x+1,y))
			visi[(x+1,y)]=1
		if x-1>=0 and y<m and ar[x-1][y]=='#' and not visi[(x-1,y)]:
			st.append((x-1,y))
			visi[(x-1,y)]=1
ans=0
for i in range(n):
	for j in range(m):
		if not visi[(i,j)] and ar[i][j]=='#':
			dfs(i,j,n,m)

			ans+=1
print(ans)