#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[1005][1005];
int a[1005], b[1005], c[1005], d[1005];
int v[1005][1005];
void dfs(int x, int y) {
  v[x][y] = 1;
  if (s[x - 1][y] == '#' && !v[x - 1][y]) dfs(x - 1, y);
  if (s[x + 1][y] == '#' && !v[x + 1][y]) dfs(x + 1, y);
  if (s[x][y - 1] == '#' && !v[x][y - 1]) dfs(x, y - 1);
  if (s[x][y + 1] == '#' && !v[x][y + 1]) dfs(x, y + 1);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= (n); ++i) scanf("%s", s[i] + 1);
  int ok = 1;
  for (int i = 1; i <= (n); ++i) {
    a[i] = b[i] = 0;
    for (int j = 1; j <= (m); ++j)
      if (s[i][j] == '#') {
        a[i] = a[i] ? a[i] : j;
        b[i] = j;
      }
    if (a[i])
      for (int j = a[i]; j <= (b[i]); ++j)
        if (s[i][j] == '.') ok = 0;
  }
  for (int j = 1; j <= (m); ++j) {
    c[j] = d[j] = 0;
    for (int i = 1; i <= (n); ++i)
      if (s[i][j] == '#') {
        c[j] = c[j] ? c[j] : i;
        d[j] = i;
      }
    if (c[j])
      for (int i = c[j]; i <= (d[j]); ++i)
        if (s[i][j] == '.') ok = 0;
  }
  if (!ok) return puts("-1"), 0;
  int _x = 0, _y = 0;
  for (int i = 1; i <= (n); ++i)
    if (!a[i]) _x = 1;
  for (int j = 1; j <= (m); ++j)
    if (!c[j]) _y = 1;
  if (_x ^ _y) return puts("-1"), 0;
  int ans = 0;
  for (int i = 1; i <= (n); ++i)
    for (int j = 1; j <= (m); ++j)
      if (s[i][j] == '#' && !v[i][j]) ++ans, dfs(i, j);
  printf("%d\n", ans);
  return 0;
}
