#include <bits/stdc++.h>
using namespace std;
bool vis[1005][1005];
char str[1005][1005];
int n, m;
queue<pair<int, int> > q;
void bfs(int sx, int sy) {
  vis[sx][sy] = 1;
  q.push(pair<int, int>(sx, sy));
  while (!q.empty()) {
    pair<int, int> t = q.front();
    q.pop();
    int x = t.first, y = t.second;
    if (x > 1 && str[x - 1][y] == '#' && !vis[x - 1][y]) {
      vis[x - 1][y] = 1;
      q.push(pair<int, int>(x - 1, y));
    }
    if (x < n && str[x + 1][y] == '#' && !vis[x + 1][y]) {
      vis[x + 1][y] = 1;
      q.push(pair<int, int>(x + 1, y));
    }
    if (y > 1 && str[x][y - 1] == '#' && !vis[x][y - 1]) {
      vis[x][y - 1] = 1;
      q.push(pair<int, int>(x, y - 1));
    }
    if (y < m && str[x][y + 1] == '#' && !vis[x][y + 1]) {
      vis[x][y + 1] = 1;
      q.push(pair<int, int>(x, y + 1));
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1);
  bool v = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (str[i][j] == '#') v = 1;
  if (!v) {
    puts("0");
    return 0;
  }
  bool r0 = 0, c0 = 0;
  for (int i = 1; i <= n; i++) {
    int s = 0;
    for (int j = 1; j <= m; j++)
      if (str[i][j] == '#' && str[i][j - 1] != '#') s++;
    if (s > 1) {
      puts("-1");
      return 0;
    }
    if (!s) r0 = 1;
  }
  for (int i = 1; i <= m; i++) {
    int s = 0;
    for (int j = 1; j <= n; j++)
      if (str[j][i] == '#' && str[j - 1][i] != '#') s++;
    if (s > 1) {
      puts("-1");
      return 0;
    }
    if (!s) c0 = 1;
  }
  if (r0 ^ c0) {
    puts("-1");
    return 0;
  }
  int s = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (str[i][j] == '#' && !vis[i][j]) {
        s++;
        bfs(i, j);
      }
  printf("%d\n", s);
  return 0;
}
