#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
int n, m;
char s[MAXN][MAXN];
void finish() {
  puts("-1");
  exit(0);
}
int bio[MAXN][MAXN];
const int smjerx[] = {1, 0, -1, 0};
const int smjery[] = {0, -1, 0, 1};
void dfs(int x, int y) {
  bio[x][y] = 1;
  for (int i = (0); i < int(4); i++) {
    int nx = x + smjerx[i];
    int ny = y + smjery[i];
    if (nx < 0 || ny < 0 || nx >= n || ny >= m || bio[nx][ny] ||
        s[nx][ny] != '#')
      continue;
    dfs(nx, ny);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = (0); i < int(n); i++) scanf("%s", s[i]);
  for (int i = (0); i < int(n); i++) {
    int cnt = 0;
    int x = -1;
    for (int j = (0); j < int(m); j++) {
      cnt += (s[i][j] == '#');
      if (s[i][j] == '#' && x == -1) x = j;
    }
    for (int j = (x); j < int(m); j++) {
      if (s[i][j] != '#') break;
      cnt--;
    }
    if (cnt)
      cerr << "i _ x _ cnt"
           << "  " << i << " " << x << " " << cnt << endl;
    if (cnt) finish();
  }
  for (int j = (0); j < int(m); j++) {
    int cnt = 0;
    int x = -1;
    for (int i = (0); i < int(n); i++) {
      cnt += (s[i][j] == '#');
      if (s[i][j] == '#' && x == -1) x = i;
    }
    for (int i = (x); i < int(n); i++) {
      if (s[i][j] != '#') break;
      cnt--;
    }
    if (cnt) finish();
  }
  set<int> cols, rows;
  for (int i = (0); i < int(n); i++) {
    for (int j = (0); j < int(m); j++) {
      if (s[i][j] == '#') {
        cols.insert(j);
        rows.insert(i);
      }
    }
  }
  if ((int)rows.size() == n && (int)cols.size() != m) finish();
  if ((int)rows.size() != n && (int)cols.size() == m) finish();
  int sol = 0;
  for (int i = (0); i < int(n); i++) {
    for (int j = (0); j < int(m); j++) {
      if (!bio[i][j] && s[i][j] == '#') {
        sol++;
        dfs(i, j);
      }
    }
  }
  printf("%d\n", sol);
  return 0;
}
