#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e3 + 7;
int n, m, flag = 1, x, y;
char s[maxx][maxx];
int vis[maxx][maxx], l[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
void bfs(int x, int y) {
  vis[x][y] = 1;
  queue<pair<int, int>> q;
  q.push(make_pair(x, y));
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int u = p.first + l[i][0], v = p.second + l[i][1];
      if (u > n || u < 1 || v < 1 || v > m || s[u][v] == '.' || vis[u][v])
        continue;
      q.push(make_pair(u, v));
      vis[u][v] = 1;
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> (s[i] + 1);
    int temp = 0;
    for (int j = 1; j < m; j++) {
      if (s[i][j] == '.' && s[i][j + 1] == '#' && temp) flag = 0;
      if (s[i][j] == '#') temp++;
    }
    if (!temp && s[i][m] != '#') x = 1;
  }
  for (int i = 1; i <= m; i++) {
    int temp = 0;
    for (int j = 1; j < n; j++) {
      if (s[j][i] == '.' && s[j + 1][i] == '#' && temp) flag = 0;
      if (s[j][i] == '#') temp++;
    }
    if (!temp && s[n][i] != '#') y = 1;
  }
  if (x + y == 1) flag = 0;
  if (!flag)
    cout << -1 << endl;
  else {
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (!vis[i][j] && s[i][j] == '#') bfs(i, j), ans++;
      }
    }
    cout << ans << endl;
  }
}
