#include <bits/stdc++.h>
using namespace std;
int dadsadasda;
const int INF = 0x3f3f3f3f;
const long long LLINF = 1e18;
const int MAXN = 1010;
const char GOOD = '#', BAD = '.';
int n, m;
vector<string> M[2];
bool valid(vector<string> &mat, int rows, int cols) {
  bool in = false, found = false;
  for (int i = 0; i < rows; i++) {
    in = found = false;
    for (int j = 0; j < cols; j++) {
      if (mat[i][j] == GOOD) {
        if (in == false && found == true) return false;
        in = true, found = true;
      } else {
        in = false;
      }
    }
  }
  return true;
}
bool full_row(vector<string> &mat, int rows, int cols) {
  for (int i = 0; i < rows; i++) {
    bool full = true;
    for (int j = 0; j < cols; j++) {
      if (mat[i][j] == GOOD) full = false;
    }
    if (full) return true;
  }
  return false;
}
bool valid(int i, int j) {
  return min(i, j) >= 0 && i < n && j < m && M[0][i][j] == GOOD;
}
void dfs(vector<string> &mat, int i, int j) {
  mat[i][j] = '-';
  for (int di : {1, 0, -1}) {
    for (int dj : {1, 0, -1}) {
      if (abs(di) == abs(dj)) continue;
      if (valid(i + di, j + dj)) dfs(mat, i + di, j + dj);
    }
  }
}
int main() {
  dadsadasda = scanf("%d %d", &n, &m);
  M[0] = vector<string>(n, string(m, '0'));
  M[1] = vector<string>(m, string(n, '0'));
  for (int i = 0; i < n; i++) {
    cin >> M[0][i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      M[1][j][n - 1 - i] = M[0][i][j];
    }
  }
  if (!valid(M[0], n, m) || !valid(M[1], m, n)) {
    printf("-1\n");
    return 0;
  }
  if (full_row(M[0], n, m) ^ full_row(M[1], m, n)) {
    printf("-1\n");
    return 0;
  }
  int comp = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (M[0][i][j] == GOOD) {
        comp++;
        dfs(M[0], i, j);
      }
    }
  }
  printf("%d\n", comp);
  return 0;
}
