import collections

def check(i,j):
    q=collections.deque()
    q.append((i,j))
    while len(q)!=0:
        i,j=q.popleft()
        if i!=0 and checked[i-1][j]==0 and board[i-1][j]=='#':
            checked[i-1][j]=1
            q.append((i-1,j))
        if i!=n-1 and checked[i+1][j]==0 and board[i+1][j]=='#':
            checked[i+1][j]=1
            q.append((i+1,j))
        if j!=0 and checked[i][j-1]==0 and board[i][j-1]=='#':
            checked[i][j-1]=1
            q.append((i,j-1))
        if j!=m-1 and checked[i][j+1]==0 and board[i][j+1]=='#':
            checked[i][j+1]=1
            q.append((i,j+1))

n,m=map(int,input().split())
board=[list(input()) for _ in range(n)]
tate=set()
yoko=set()
for i in range(n):
    flag=0
    for j in range(m):
        if board[i][j]=='#':
            yoko.add(i)
            tate.add(j)
            if flag==0:
                flag=1
            if flag==2:
                print(-1)
                exit()
        if board[i][j]=='.' and flag==1:
            flag=2
for i in range(m):
    flag=0
    for j in range(n):
        if board[j][i]=='#':
            if flag==0:
                flag=1
            if flag==2:
                print(-1)
                exit()
        if board[j][i]=='.' and flag==1:
            flag=2
for i in range(n):
    if i in yoko:
        continue
    flag=False
    for j in range(m):
        if j not in tate:
            flag=True
    if flag==False:
        print(-1)
        exit()
for i in range(m):
    if i in tate:
        continue
    flag=False
    for j in range(n):
        if j not in yoko:
            flag=True
    if flag==False:
        print(-1)
        exit()
cnt=0
checked=[[0]*m for _ in range(n)]
for i in range(n):
    for j in range(m):
        if board[i][j]=='.' or checked[i][j]==1:
            continue
        else:
            cnt+=1
            checked[i][j]=1
            check(i,j)
print(cnt)