#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int p[N * N];
int f(int u) { return u == p[u] ? u : p[u] = f(p[u]); }
bool join(int a, int b) {
  a = f(a), b = f(b);
  if (a == b) return false;
  p[a] = b;
  return true;
}
int n, m;
char mat[N][N];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool possible() {
  int freer = 0, freec = 0;
  for (int i = 0; i < n; i++) {
    int j = 0;
    while (j < m and mat[i][j] == '.') j++;
    if (j == m) {
      freer++;
    } else {
      while (j < m and mat[i][j] == '#') j++;
      while (j < m and mat[i][j] == '.') j++;
      if (j < m) return false;
    }
  }
  for (int j = 0; j < m; j++) {
    int i = 0;
    while (i < n and mat[i][j] == '.') i++;
    if (i == n) {
      freec++;
    } else {
      while (i < n and mat[i][j] == '#') i++;
      while (i < n and mat[i][j] == '.') i++;
      if (i < n) return false;
    }
  }
  if (freer == freec) return true;
  if (!freer or !freec) return false;
  return true;
  return (freer > 0) == (freec > 0);
}
int main() {
  iota(p, p + N * N, 0);
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf(" %s", mat[i]);
  int cnt = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (mat[i][j] != '#') continue;
      cnt++;
      for (int k = 0; k < 4; k++) {
        int x = i + dx[k], y = j + dy[k];
        if (x < 0 or x >= n or y < 0 or y >= m) continue;
        if (mat[x][y] != '#') continue;
        cnt -= join(i * N + j, x * N + y);
      }
    }
  if (!possible()) {
    printf("-1\n");
    return 0;
  }
  printf("%d\n", cnt);
}
