#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
const long long mod = 998244353;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0', ch = getchar();
  }
  return x * f;
}
int n, m, l[N], r[N], vis[N][N];
char s[N][N];
void dfs(int x, int y) {
  vis[x][y] = 1;
  if (s[x + 1][y] == '#' && !vis[x + 1][y]) dfs(x + 1, y);
  if (s[x - 1][y] == '#' && !vis[x - 1][y]) dfs(x - 1, y);
  if (s[x][y + 1] == '#' && !vis[x][y + 1]) dfs(x, y + 1);
  if (s[x][y - 1] == '#' && !vis[x][y - 1]) dfs(x, y - 1);
}
void solve() {
  n = read();
  m = read();
  int cntx = 0, cnty = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
    int vis = 0;
    for (int j = 1; j <= m; j++) {
      if (!vis && s[i][j] == '#')
        vis = 1, l[i] = j;
      else if (vis == 1 && s[i][j] == '.')
        vis = 2, r[i] = j - 1;
      else if (vis == 2 && s[i][j] == '#')
        vis = -1;
      if (vis == -1) {
        puts("-1");
        return;
      }
    }
    if (vis != 0) cntx++;
    if (l[i] && !r[i]) r[i] = m;
  }
  for (int i = 1; i <= m; i++) {
    int vis = 0;
    for (int j = 1; j <= n; j++) {
      if (!vis && s[j][i] == '#')
        vis = 1;
      else if (vis == 1 && s[j][i] == '.')
        vis = 2;
      else if (vis == 2 && s[j][i] == '#')
        vis = -1;
      if (vis == -1) {
        puts("-1");
        return;
      }
    }
    if (vis != 0) cnty++;
  }
  if ((cntx == n) ^ (cnty == m)) {
    puts("-1");
    return;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '#' && !vis[i][j]) dfs(i, j), ans++;
    }
  }
  printf("%d\n", ans);
}
int main() {
  int T = 1;
  while (T--) solve();
}
