import sys
n, m = map(int, input().split())
s = []
for _ in range(n):
    s.append(input())
w_row = False
for i in s:
    stat = 0
    for j in i:
        if stat==0 and j=='#':
            stat = 1
        elif stat==1 and j=='.':
            stat = 2
        elif stat==2 and j=='#':
            print(-1)
            sys.exit()
    if stat==0:
        w_row = True
w_col = False
pb = pe = -1
ans = 0
for i in range(m):
    stat = 0
    for j in range(n):
        if stat==0 and s[j][i]=='#':
            stat = 1
            b = j
        elif stat==1 and s[j][i]=='.':
            stat = 2
            e = j-1
        elif stat==2 and s[j][i]=='#':
            print(-1)
            sys.exit()
    if stat==0:
        w_col = True
        pb = pe = -1
    if stat==1:
        e = n-1
    if stat>0:
        if e<pb or pe<b:
            ans += 1
        pb, pe = b, e

if w_row^w_col:
    print(-1)
else:
    print(ans)