#include <bits/stdc++.h>
using namespace std;
char a[1005][1005];
int visited[1005][1005];
int b[1005][1005];
int r[1005] = {0};
int c[1005] = {0};
long long n, m;
int solve(int x, int y) {
  int count = 0;
  if (y == -1) {
    for (int j = 0; j < m; j++)
      if (b[x][j] != 0) count++;
    if (!count && !r[x]) return 0;
    int temp = r[x];
    for (int j = 0; j < m; j++) {
      if (a[x][j] == '.' && temp && temp != r[x])
        return 0;
      else if (a[x][j] == '#')
        temp--;
    }
  } else {
    for (int j = 0; j < n; j++)
      if (b[j][y] != 0) count++;
    if (!count && !c[y]) return 0;
    int temp = c[y];
    for (int j = 0; j < n; j++) {
      if (a[j][y] == '.' && temp && temp != c[y])
        return 0;
      else if (a[j][y] == '#')
        temp--;
    }
  }
}
void dfs(int x, int y) {
  if (x < 0 || y < 0 || x >= n || y >= m || a[x][y] == '.') return;
  if (visited[x][y] == 1) return;
  visited[x][y] = 1;
  dfs(x + 1, y);
  dfs(x, y + 1);
  dfs(x, y - 1);
  dfs(x - 1, y);
}
void getvalues() {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (a[i][j] == '#') r[i]++, c[j]++;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (r[i] == 0 && c[j] == 0) b[i][j] = 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, l, q, t, h, p, k;
  std::cin >> n >> m;
  h = 0;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) std::cin >> a[i][j];
  if (n == 1 && m == 1) {
    if (a[0][0] == '#')
      std::cout << 1 << std::endl;
    else
      std::cout << 0 << std::endl;
  } else if (n == 1 || m == 1)
    std::cout << -1 << std::endl;
  else {
    getvalues();
    for (i = 0; i < n; i++) {
      if (solve(i, -1) == 0) break;
    }
    if (i < n)
      std::cout << -1 << std::endl;
    else {
      for (i = 0; i < m; i++) {
        if (solve(-1, i) == 0) break;
      }
      if (i < m)
        std::cout << -1 << std::endl;
      else {
        memset(visited, 0, sizeof(visited));
        p = 0;
        for (i = 0; i < n; i++) {
          for (j = 0; j < m; j++) {
            if (a[i][j] == '#' && visited[i][j] == 0) {
              p++;
              dfs(i, j);
            }
          }
        }
        std::cout << p << std::endl;
      }
    }
  }
  return 0;
}
