#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline long long squ(T x) {
  return (long long)x * x;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline T read() {
  T sum = 0, fg = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') fg = -1;
  for (; isdigit(c); c = getchar()) sum = (sum << 3) + (sum << 1) + (c ^ 0x30);
  return fg * sum;
}
const int maxn = 1e3 + 10;
char S[maxn];
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
bitset<maxn> L, C;
int n, m;
bitset<maxn> g[maxn];
inline bool chk(int x, int y) {
  if (g[x][y] || (!L[x] && !C[y])) return 1;
  return 0;
}
inline void dfs(int x, int y) {
  g[x][y] = 0;
  for (int k = 0; k < 4; k++) {
    int i = x + dx[k], j = y + dy[k];
    if (g[i][j]) dfs(i, j);
  }
}
int main() {
  n = read<int>(), m = read<int>();
  bool hk = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%s", S + 1);
    for (int j = 1; j <= m; j++) {
      g[i][j] = S[j] == '#' ? 1 : 0;
      if (g[i][j] == 1) hk = 1, L[i] = 1, C[j] = 1;
    }
  }
  if (!hk) {
    printf("0\n");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    bool ok = 0, dio = 0;
    for (int j = 1; j <= m; j++) {
      if (chk(i, j)) dio = 1;
      if (ok && g[i][j] && !g[i][j - 1]) {
        printf("-1\n");
        return 0;
      }
      if (g[i][j]) ok = 1;
    }
    if (!dio) {
      printf("-1\n");
      return 0;
    }
  }
  for (int j = 1; j <= m; j++) {
    bool ok = 0, dio = 0;
    for (int i = 1; i <= n; i++) {
      if (chk(i, j)) dio = 1;
      if (ok && g[i][j] && !g[i - 1][j]) {
        printf("-1\n");
        return 0;
      }
      if (g[i][j]) ok = 1;
    }
    if (!dio) {
      printf("-1\n");
      return 0;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (g[i][j]) dfs(i, j), ++cnt;
  printf("%d\n", cnt);
  return 0;
}
