#include <bits/stdc++.h>
using namespace std;
int n, m;
bool isvalid(int i, int j) {
  if (i >= 0 and i < n and j >= 0 and j < m) return true;
  return false;
}
void dfs(int i, int j, int x, vector<vector<int> > &vis,
         vector<vector<int> > &v) {
  vis[i][j] = x;
  if (isvalid(i + 1, j) and !vis[i + 1][j] and v[i + 1][j] == '#')
    dfs(i + 1, j, x, vis, v);
  if (isvalid(i - 1, j) and !vis[i - 1][j] and v[i - 1][j] == '#')
    dfs(i - 1, j, x, vis, v);
  if (isvalid(i, j + 1) and !vis[i][j + 1] and v[i][j + 1] == '#')
    dfs(i, j + 1, x, vis, v);
  if (isvalid(i, j - 1) and !vis[i][j - 1] and v[i][j - 1] == '#')
    dfs(i, j - 1, x, vis, v);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  vector<vector<int> > v(n, vector<int>(m)), vis(n, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    string str;
    cin >> str;
    for (int j = 0; j < m; ++j) {
      v[i][j] = str[j];
    }
  }
  int x = 1, f = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (!vis[i][j] and v[i][j] == '#') {
        dfs(i, j, x, vis, v);
        x++;
      }
    }
  }
  vector<int> sr(n), sc(m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      sr[i] += vis[i][j];
      sc[j] += vis[i][j];
    }
  }
  int r = 0, c = 0;
  for (int i = 0; i < n; ++i) {
    if (sr[i] == 0) r++;
    int l = 0, r = m - 1;
    while (l < m and vis[i][l] == 0) l++;
    while (r >= 0 and vis[i][r] == 0) r--;
    for (int k = l; k <= r; ++k) {
      if (vis[i][k] == 0) f = 0;
    }
  }
  for (int j = 0; j < m; ++j) {
    if (sc[j] == 0) c++;
    int l = 0, r = n - 1;
    while (l < n and vis[l][j] == 0) l++;
    while (r >= 0 and vis[r][j] == 0) r--;
    for (int k = l; k <= r; ++k) {
      if (vis[k][j] == 0) f = 0;
    }
  }
  if ((r == 0 ^ c == 0) or !f) {
    cout << "-1\n";
  } else
    cout << x - 1 << '\n';
}
