#include <bits/stdc++.h>
using namespace std;
bool checkCol(vector<string>& v, int n) {
  bool flag = true;
  for (long long((i)) = (0); ((i)) < ((v.size())); ((i))++) {
    if (v[i][n] != '.') flag = false;
  }
  return flag;
}
void dfs(vector<vector<int>>& v, int i, int j) {
  v[i][j] = 1;
  if (i + 1 < v.size() && !v[i + 1][j]) dfs(v, i + 1, j);
  if (j + 1 < v[i].size() && !v[i][j + 1]) dfs(v, i, j + 1);
  if (i && !v[i - 1][j]) dfs(v, i - 1, j);
  if (j && !v[i][j - 1]) dfs(v, i, j - 1);
}
void perform() {
  int n, m;
  cin >> n >> m;
  vector<string> g;
  vector<vector<int>>(v)((n), vector<int>(m));
  ;
  for (long long((i)) = (0); ((i)) < ((n)); ((i))++) {
    string s;
    cin >> s;
    g.push_back(s);
    for (long long((j)) = (0); ((j)) < ((m)); ((j))++) {
      if (s[j] == '.') {
        v[i][j] = -1;
      }
    }
  }
  for (long long((i)) = (0); ((i)) < ((n)); ((i))++) {
    if (g[i] == string(m, '.')) {
      for (long long((j)) = (0); ((j)) < ((m)); ((j))++) v[i][j] = 1;
    } else {
      bool flag = false;
      for (long long(j) = (1); (j) < (m); (j)++) {
        if (g[i][j] == '.' && g[i][j - 1] == '#') {
          flag = true;
        }
        if (flag && g[i][j] == '#') {
          cout << -1 << endl;
          return;
        }
      }
    }
  }
  for (long long((i)) = (0); ((i)) < ((m)); ((i))++) {
    if (checkCol(g, i)) {
      for (long long((j)) = (0); ((j)) < ((n)); ((j))++) {
        if (v[j][i] == 1) v[j][i] = 2;
      }
    } else {
      bool flag = false;
      if (v[0][i] == 1) v[0][i] = -1;
      for (long long(j) = (1); (j) < (n); (j)++) {
        if (v[j][i] == 1) v[j][i] = -1;
        if (g[j][i] == '.' && g[j - 1][i] == '#') {
          flag = true;
        }
        if (flag && g[j][i] == '#') {
          cout << -1 << endl;
          return;
        }
      }
    }
  }
  int rmark[n];
  int cmark[m];
  memset(rmark, 0, sizeof(rmark));
  memset(cmark, 0, sizeof(cmark));
  for (long long((i)) = (0); ((i)) < ((n)); ((i))++) {
    for (long long((j)) = (0); ((j)) < ((m)); ((j))++) {
      if (v[i][j] != -1) {
        rmark[i] = 1;
        cmark[j] = 1;
      }
    }
  }
  for (long long((i)) = (0); ((i)) < ((n)); ((i))++) {
    if (!rmark[i]) {
      cout << -1 << endl;
      return;
    }
  }
  for (long long((i)) = (0); ((i)) < ((m)); ((i))++) {
    if (!cmark[i]) {
      cout << -1 << endl;
      return;
    }
  }
  int count = 0;
  for (long long((i)) = (0); ((i)) < ((n)); ((i))++) {
    for (long long((j)) = (0); ((j)) < ((m)); ((j))++) {
      if (!v[i][j]) dfs(v, i, j), count++;
    }
  }
  cout << count << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    perform();
  }
}
