n,m=map(int,input().split())
matrix=[]
for i in range(n):
    col=[i for i in input()]
    matrix.append(col)
#print(matrix)
count=0
col_store=[0]*(m)
store=[0]*(m)
zerocol,zerorow=0,0
for i in range(n):
    hash_,dot,check=False,False,False
    for j in range(m):
        if hash_==True and dot==True and matrix[i][j]=='#' and matrix[i][j-1]=='.':
            #print(i,j,store)
            print(-1)
            exit()
        if col_store[j]==1 and store[j]==0 and matrix[i][j]=='#':
            #print(1)
            print(-1)
            exit()
        if store[j]==1 and matrix[i][j]=='#':
            check=True
            hash_=True
            col_store[j]=1
        if matrix[i][j]=='#' and store[j]!=1:
            hash_=True
            store[j]=1
            col_store[j]=1
        if matrix[i][j]=='.':
            dot=True
            store[j]=0
        #print(store,i,j)
    if hash_==False:
        zerorow+=1
    if check==False and hash_==True:
        count+=1
if 0 in col_store:
    zerocol+=1
if (zerocol>0 and zerorow==0) or (zerocol==0 and zerorow>0):
    print(-1)
    exit()
print(count)
    
            
        
