#include <bits/stdc++.h>
using namespace std;
char ch[2001][2001];
bool vis[2001][2001];
int Min[2][2001];
int Max[2][2001];
int emptyRows = 0;
int emptyCols = 0;
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
int n, m;
void dfs(int x, int y) {
  vis[x][y] = true;
  for (int i = 0; i < 4; ++i) {
    int nx = x + dx[i], ny = y + dy[i];
    if (nx >= 0 && nx < n && ny >= 0 && ny < m && !vis[nx][ny] &&
        ch[nx][ny] == '#') {
      dfs(nx, ny);
    }
  }
}
bool checkBWB() {
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (ch[i][j] != '#') {
        if (Min[0][i] < j && Max[0][i] > j) return true;
        if (Min[1][j] < i && Max[1][j] > i) return true;
      }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", ch[i]);
  memset(Min, 0x3f, sizeof(Min));
  memset(Max, -1, sizeof(Max));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (ch[i][j] == '#') {
        Max[0][i] = max(Max[0][i], j);
        Min[0][i] = min(Min[0][i], j);
        Max[1][j] = max(Max[1][j], i);
        Min[1][j] = min(Min[1][j], i);
      }
  for (int i = 0; i < n; ++i)
    if (Max[0][i] == -1) emptyRows++;
  for (int j = 0; j < m; ++j)
    if (Max[1][j] == -1) emptyCols++;
  bool bwb = checkBWB();
  int cnt = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (ch[i][j] == '#' && !vis[i][j]) {
        dfs(i, j);
        ++cnt;
      }
  if (bwb) {
    puts("-1");
    return 0;
  }
  if (emptyCols > 0 && emptyRows == 0) {
    puts("-1");
    return 0;
  }
  if (emptyRows > 0 && emptyCols == 0) {
    puts("-1");
    return 0;
  }
  printf("%d\n", cnt);
}
