

def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))

def print_table(title, table):
    print(title)
    for row in table:
        print(list(map(int, row)))


def validate(grid):
    n, m = len(grid), len(grid[0])
    has_left = [[False]*m for _ in range(n)]
    has_right = [[False]*m for _ in range(n)]
    has_top = [[False]*m for _ in range(n)]
    has_bottom = [[False]*m for _ in range(n)]
    for i in range(n):
        for j in range(m):
            if j == 0:
                has_left[i][j] = grid[i][j] == '#'
            else:
                has_left[i][j] = has_left[i][j-1] or grid[i][j] == '#'
            if j == 0:
                has_right[i][m-1-j] = grid[i][m-1-j] == '#'
            else:
                has_right[i][m-1-j] = has_right[i][m-j] or grid[i][m-1-j] == '#'
    for j in range(m):
        for i in range(n):
            if i == 0:
                has_top[i][j] = grid[i][j] == '#'
            else:
                has_top[i][j] = has_top[i-1][j] or grid[i][j] == '#'
            if i == 0:
                has_bottom[n-1-i][j] = grid[n-i-1][j] == '#'
            else:
                has_bottom[n-1-i][j] = has_bottom[n-i][j] or grid[n-i-1][j] == '#'
    for i in range(n):
        for j in range(m):
            if grid[i][j] == '.' and ((has_left[i][j] and has_right[i][j]) or (has_top[i][j] and has_bottom[i][j])):
                return False
    for i in range(n):
        if not has_right[i][0]:
            # check
            achievable = False
            for j in range(m):
                if not has_top[i][j] and not has_bottom[i][j]:
                    achievable = True
                    break
            if not achievable:
                return False

    for j in range(m):
        if not has_bottom[0][j]:
            # check
            achievable = False
            for i in range(n):
                if not has_left[i][j] and not has_right[i][j]:
                    achievable = True
                    break
            if not achievable:
                return False
    return True


def solve():
    n, m = read_ints()
    grid = []
    for _ in range(n):
        grid.append(list(input().strip()))
    if not validate(grid):
        return -1
    count = 0
    for i in range(n):
        for j in range(m):
            if grid[i][j] == '#':
                count += 1
                # do dfs
                Q = [(i, j)]
                while len(Q):
                    i, j = Q.pop()
                    for x, y in [(i-1, j), (i+1, j), (i, j-1), (i, j+1)]:
                        if 0 <= x < n and 0 <= y < m and grid[x][y] == '#':
                            grid[x][y] = '.'
                            Q.append((x, y))
    return count


if __name__ == '__main__':
    print(solve())
