from collections import deque
 
n, m = map(int, input().split())
array = []
for i in range(n):
    array.append(input())
 
solution_possible = True
white_row = False
white_column = False
 
for i in range(n):
  black_found = False
  all_white = True
  for j in range(m):
    if array[i][j] == '#':
      all_white = False
      if black_found:
        solution_possible = False
      if j < m - 1 and array[i][j + 1] == '.':
        black_found = True
  if all_white:
    white_row = True
 
for j in range(m):
  black_found = False
  all_white = True
  for i in range(n):
    if array[i][j] == '#':
      all_white = False
      if black_found:
        solution_possible = False
      if i < n - 1 and array[i + 1][j] == '.':
        black_found = True
  if all_white:
    white_column = True
 
if white_row or white_column:
  if not white_row:
    solution_possible = False
  if not white_column:
    solution_possible = False
 
if not solution_possible:
  print(-1)
else:
  visited = [[False] * m for _ in range(n)]
  dx = [-1, 1, 0, 0]
  dy = [0, 0, -1, 1]
 
  def bfs(x, y):
      queue = deque([(x, y)])
      visited[x][y] = True
      while queue:
        x, y = queue.popleft()
        for i in range(4):
          nx = x + dx[i]
          ny = y + dy[i]
          if nx < 0 or ny < 0 or nx >= n or ny >= m:
            continue
          if array[x][y] == '#' and not visited[nx][ny]:
            visited[nx][ny] = True
            queue.append((nx, ny))
 
  result = 0
  for i in range(n):
      for j in range(m):
          if array[i][j] == '#' and not visited[i][j]:
              bfs(i, j)
              result += 1
  print(result) 