#include <bits/stdc++.h>
using namespace std;
const int64_t INF = 1e18, MOD = 1e9 + 7;
bool check(vector<vector<bool> >& b) {
  int64_t n = b.size(), m = b[0].size();
  vector<bool> col(m, 0);
  for (int64_t i = 0; i < n; i++)
    for (int64_t j = 0; j < m; j++)
      if (b[i][j]) col[j] = 1;
  bool empc = 0;
  for (int64_t j = 0; j < m; j++)
    if (col[j] == 0) empc = 1;
  for (int64_t i = 0; i < n; i++) {
    bool in = 0, was = 0;
    for (int64_t j = 0; j < m; j++) {
      if (!b[i][j]) {
        if (in) was = 1;
        in = 0;
      } else {
        if (in) continue;
        if (was) return 0;
        in = 1;
      }
    }
    if (in) was = 1;
    if (!was & !empc) return 0;
  }
  return 1;
}
int64_t n, m;
vector<vector<bool> > b;
pair<int64_t, int64_t> dir[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
void dfs(pair<int64_t, int64_t> p) {
  if (p.first < 0 || p.second < 0 || p.first >= n || p.second >= m) return;
  if (!b[p.first][p.second]) return;
  b[p.first][p.second] = 0;
  for (int64_t i = 0; i < 4; i++) {
    dfs({p.first + dir[i].first, p.second + dir[i].second});
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  b.resize(n, vector<bool>(m));
  vector<vector<bool> > b2(m, vector<bool>(n));
  for (int64_t i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int64_t j = 0; j < m; j++) b[i][j] = b2[j][i] = s[j] == '#';
  }
  if (!check(b)) return cout << -1 << endl, 0;
  if (!check(b2)) return cout << -1 << endl, 0;
  int64_t ans = 0;
  for (int64_t i = 0; i < n; i++)
    for (int64_t j = 0; j < m; j++)
      if (b[i][j]) dfs({i, j}), ans++;
  cout << ans << endl;
  return 0;
}
