#include <bits/stdc++.h>
using namespace std;
const int N = 1004;
char a[N][N];
int num[N][N], vis[N * N], mark[N * N], n, m, val = 1;
vector<int> adj[N * N];
void dfs(int node) {
  vis[node] = true;
  int i;
  for (i = 0; i < adj[node].size(); ++i) {
    if (!vis[adj[node][i]]) {
      dfs(adj[node][i]);
    }
  }
}
int main() {
  int i, j, f1, f2, ans = 0, r = 0, c = 0, d;
  cin >> n >> m;
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) {
      cin >> a[i][j];
      num[i][j] = val;
      ++val;
    }
  for (i = 1; i <= n; ++i)
    for (j = 1, f1 = f2 = 0; j <= m; ++j) {
      if (a[i][j] == '#' && !f1)
        f1 = 1;
      else if (f1 && f2 && a[i][j] == '#')
        ans = -1;
      else if (a[i][j] == '.' && f1)
        f2 = 1;
    }
  for (i = 1; i <= m; ++i)
    for (j = 1, f1 = f2 = 0; j <= n; ++j) {
      if (a[j][i] == '#' && !f1)
        f1 = 1;
      else if (f1 && f2 && a[j][i] == '#')
        ans = -1;
      else if (a[j][i] == '.' && f1)
        f2 = 1;
    }
  for (i = 1; i <= n; ++i) {
    f1 = 0;
    for (j = 1; j <= m; ++j) {
      if (a[i][j] == '#') f1 = 1;
    }
    if (f1 == 0) r = 1;
  }
  for (i = 1; i <= m; ++i) {
    f1 = 0;
    for (j = 1; j <= n; ++j) {
      if (a[j][i] == '#') f1 = 1;
    }
    if (f1 == 0) c = 1;
  }
  if (r != c) ans = -1;
  if (ans == -1) {
    cout << ans;
    return 0;
  }
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) {
      if (a[i][j] == '#') {
        c = i - 1, d = j;
        mark[num[i][j]] = 1;
        if (c != 0 && a[c][d] == '#') {
          mark[num[c][d]] = 1;
          adj[num[i][j]].push_back(num[c][d]);
          adj[num[c][d]].push_back(num[i][j]);
        }
        c = i, d = j + 1;
        if (d <= m && a[c][d] == '#') {
          mark[num[c][d]] = 1;
          adj[num[i][j]].push_back(num[c][d]);
          adj[num[c][d]].push_back(num[i][j]);
        }
      }
    }
  ans = 0;
  for (i = 1; i <= N * N; ++i) {
    if (mark[i] && !vis[i]) {
      ++ans;
      dfs(i);
    }
  }
  cout << ans << "\n";
  return 0;
}
