#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1);
const int M = 1e3 + 10;
const int inf = 2e9 + 10;
const int mod = 998244353;
int n, m;
int f[M][M];
int a[4] = {1, -1, 0, 0};
int b[4] = {0, 0, 1, -1};
void dfs(int x, int y) {
  f[x][y] = 0;
  for (int i = 0; i < 4; ++i)
    if (f[x + a[i]][y + b[i]]) {
      dfs(x + a[i], y + b[i]);
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      char c;
      cin >> c;
      if (c == '#')
        f[i][j] = 1;
      else
        f[i][j] = 0;
    }
  int rseg = 0, cseg = 0;
  for (int i = 1; i <= n; ++i) {
    int seg = 0;
    for (int j = 1; j <= m; ++j)
      if (f[i][j] == 1 && f[i][j - 1] == 0) ++seg;
    if (seg > 1) {
      cout << "-1\n";
      return 0;
    }
    if (seg) ++rseg;
  }
  for (int i = 1; i <= m; ++i) {
    int seg = 0;
    for (int j = 1; j <= n; ++j)
      if (f[j][i] == 1 && f[j - 1][i] == 0) ++seg;
    if (seg > 1) {
      cout << "-1\n";
      return 0;
    }
    if (seg) ++cseg;
  }
  if (rseg == n && cseg != m || cseg == m && rseg != n) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (f[i][j]) {
        dfs(i, j);
        ++ans;
      }
  cout << ans << '\n';
}
