def main():

    import sys, math
    #from bisect import bisect_left as bl, bisect_right as br, insort
    #from heapq import heapify, heappush, heappop
    from collections import defaultdict as dd, deque
    def data(): return sys.stdin.readline().strip()
    def mdata(): return list(map(int, data().split()))
    def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
    # sys.setrecursionlimit(100000)
    INF = int(1e9)
    mod = int(1e9)+7

    def find(x):
        while Group[x] != x:
            x = Group[x]
        return x

    def Union(x, y):
        if find(x) != find(y):

            if Nodes[find(x)] < Nodes[find(y)]:
                Nodes[find(y)] += Nodes[find(x)]
                Nodes[find(x)] = 0
                Group[find(x)] = find(y)

            else:
                Nodes[find(x)] += Nodes[find(y)]
                Nodes[find(y)] = 0
                Group[find(y)] = find(x)

    n, m = mdata()
    Group = []
    for i in range(n):
        for j in range(m):
            Group.append(i*m+j)
    Nodes = [1] * (n*m)
    mat = []
    for i in range(n):
        mat.append(data())
    mc=[-1]*m
    mr=[-1]*n
    s=set()
    for i in range(n):
        for j in range(m):
            if mat[i][j]=='#':
                if i>0:
                    if mat[i-1][j]=='#':
                        Union(find(i*m+j),find((i-1)*m+j))
                if j>0:
                    if mat[i][j-1]=='#':
                        Union(find(i*m+j),find(i*m+j-1))
                if mr[i]==-1:
                    mr[i]=j
                else:
                    if mr[i]!=j-1:
                        print(-1)
                        exit()
                    mr[i]=j
                if mc[j]==-1:
                    mc[j]=i
                else:
                    if mc[j]!=i-1:
                        print(-1)
                        exit()
                    mc[j]=i
    k1=min(mr)
    k2=min(mc)
    if min(k1,k2)==-1 and max(k1,k2)!=-1:
        print(-1)
        exit()
    s=set()
    for i in range(n):
        for j in range(m):
            if mat[i][j]=='#':
                s.add(find(i*m+j))
    print(len(s))

if __name__ == '__main__':
    main()
