#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double pii = 2 * pi;
const double eps = 1e-6;
const long long MOD = 1e9 + 7;
vector<pair<int, int>> pt{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
void dfs(int x, int y, vector<string>& gr, vector<vector<bool>>& vis,
         vector<vector<int>>& p, int par) {
  if (vis[x][y] && gr[x][y] == '#') {
    vis[x][y] = false;
    p[x][y] = par;
    for (int i = 0; i < 4; i++) {
      if (x + pt[i].first >= 0 && x + pt[i].first < gr.size() &&
          y + pt[i].second >= 0 && y + pt[i].second < gr[0].size())
        dfs(x + pt[i].first, y + pt[i].second, gr, vis, p, par);
    }
  }
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<string> grid(n);
  for (int i = 0; i < n; i++) cin >> grid[i];
  vector<vector<pair<int, int>>> dp(n, vector<pair<int, int>>(m, {-1, -1}));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] == '#')
        dp[i][j].first = j;
      else if (j > 0)
        dp[i][j].first = dp[i][j - 1].first;
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      if (grid[i][j] == '#')
        dp[i][j].second = i;
      else if (i > 0)
        dp[i][j].second = dp[i - 1][j].second;
    }
  }
  bool flag = true;
  vector<bool> v1(n, false), v2(m, false);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] == '.') {
        if (i + 1 < n && grid[i + 1][j] == '#' && dp[i][j].second != -1)
          flag = false;
        if (j + 1 < m && grid[i][j + 1] == '#' && dp[i][j].first != -1)
          flag = false;
      } else {
        cnt++;
        v1[i] = true;
        v2[j] = true;
      }
    }
  }
  if (cnt == 0) {
    cout << 0 << "\n";
    return;
  }
  bool f = true;
  for (int i = 0; i < n; i++) f = (f && v1[i]);
  for (int i = 0; i < m; i++) f = (f && v2[i]);
  if (!f) {
    bool t1 = false, t2 = false;
    for (int i = 0; i < n; i++)
      if (!v1[i]) t1 = true;
    for (int i = 0; i < m; i++)
      if (!v2[i]) t2 = true;
    f = (t1 && t2);
  }
  if (flag && f) {
    vector<vector<int>> gr(n, vector<int>(m, -1)), ans(n, vector<int>(m, 0));
    vector<vector<bool>> vis(n, vector<bool>(m, true));
    int ctr = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (vis[i][j] && grid[i][j] == '#') dfs(i, j, grid, vis, gr, ctr++);
      }
    }
    cout << ctr << "\n";
  } else {
    cout << "-1\n";
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  solve();
  return 0;
}
