#include <bits/stdc++.h>
using namespace std;
const int N = 1111;
int n, m;
char a[N][N];
bool h[N][N];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
void dfs(int x, int y) {
  h[x][y] = 1;
  for (int d = 0; d < 4; d++) {
    int nx = x + dx[d];
    int ny = y + dy[d];
    if (1 <= nx and nx <= n and 1 <= ny and ny <= m and !h[nx][ny] and
        a[nx][ny]) {
      dfs(nx, ny);
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", a[i] + 1);
    for (int j = 1; j <= m; j++) {
      a[i][j] = (a[i][j] == '#');
    }
  }
  for (int i = 1; i <= n; i++) {
    bool started = false, finished = false;
    for (int j = 1; j <= m; j++) {
      if (a[i][j] and !started) started = true;
      if (a[i][j] and finished) {
        puts("-1");
        return 0;
      }
      if (!a[i][j] and started) finished = true;
    }
  }
  for (int j = 1; j <= m; j++) {
    bool started = false, finished = false;
    for (int i = 1; i <= n; i++) {
      if (a[i][j] and !started) started = true;
      if (a[i][j] and finished) {
        puts("-1");
        return 0;
      }
      if (!a[i][j] and started) finished = true;
    }
  }
  vector<bool> row(n + 1), col(m + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j]) {
        row[i] = 1;
        col[j] = 1;
      }
    }
  }
  bool empty_row = 0, empty_col = 0;
  for (int i = 1; i <= n; i++) empty_row |= !row[i];
  for (int i = 1; i <= m; i++) empty_col |= !col[i];
  if (empty_row ^ empty_col) {
    puts("-1");
    return 0;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (!h[i][j] and a[i][j]) {
        dfs(i, j);
        ans++;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
