from collections import deque
def sort_col(val):
    return val[1]

def get_bpos(a):
    rows = set()
    cols = set()
    bpos = []
    n = len(a)
    m = len(a[0])

    for i in range(n):
        for j in range(m):
            if a[i][j] == "#":
                bpos.append((i,j))
                rows.add(i)
                cols.add(j)
    return bpos, rows, cols

def is_possible(a):
    # all whites either present ins ame row/col as black in is not possible

    # if whites come in betwwen blacks then the whole row is bad which can be false
     
    n = len(a)
    m = len(a[0])
    bpos, rows, cols = get_bpos(a)
    bpos.sort()
    for val1, val2 in zip(bpos, bpos[1:]):
        if val1[0] == val2[0] and abs(val1[1]-val2[1]) != 1:
            return 0
    
    bpos.sort(key=sort_col)
    for val1, val2 in zip(bpos, bpos[1:]):
        if val1[1] == val2[1] and abs(val1[0]-val2[0]) != 1:
            return 0

    possible = [[1]*m for i in range(n)]

    for i in rows:
        for j in range(m):
            if a[i][j] == '.':
                possible[i][j] = 0
    
    for j  in cols:
        for i in range(n):
            if a[i][j] == ".":
                possible[i][j] = 0
    
    for i in range(n):
        if not any(possible[i]):
            return False
    
    for j in range(m):
        if not any(possible[i][j] == 1 for i in range(n)):
            return False

    return True

def get_nc(a):
    n = len(a)
    m = len(a[0])
    seen = [[0]*m for _ in range(n)]
    nc = 0
    q = deque()

    for i in range(n):
        for j in range(m):
            if seen[i][j] or a[i][j] == '.':
                continue
            q.append((i,j))
            seen[i][j] = 1
            while q:
                x, y = q.pop()
                if x-1 >= 0 and a[x-1][y] == '#' and (not seen[x-1][y]):
                    q.append((x-1,y))
                    seen[x-1][y] = 1
                if x+1 < n and a[x+1][y] == '#' and (not seen[x+1][y]):
                    q.append((x+1,y))
                    seen[x+1][y] = 1
                if y-1 >= 0 and a[x][y-1] == '#' and (not seen[x][y-1]):
                    q.append((x,y-1))
                    seen[x][y-1] = 1
                if y+1 < m and a[x][y+1] == '#' and (not seen[x][y+1]):
                    q.append((x,y+1))
                    seen[x][y+1] = 1
            nc += 1

    return nc
                  
n, m = map(int, input().split())
a = []
for _ in range(n):
    a.append(input())

# is every row and col has 
if not is_possible(a):
    print("-1")
else:
    # # no of connected componenets of #
    n_c = get_nc(a)
    print(n_c)

# print(n_c)