#include <bits/stdc++.h>
using namespace std;
void Fast_IO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
}
struct dir {
  bool left, right, up, down;
};
int n, m;
int a[1001][1001];
int vis[1001][1001];
vector<vector<dir> > is;
void dfs(long long x, long long y) {
  if (x < 0 || x >= n || y < 0 || y >= m) return;
  if (a[x][y] == 0) return;
  if (vis[x][y]) return;
  vis[x][y] = 1;
  dfs(x + 1, y);
  dfs(x - 1, y);
  dfs(x, y + 1);
  dfs(x, y - 1);
}
int main() {
  Fast_IO();
  cin >> n >> m;
  dir dummy;
  dummy.left = dummy.right = dummy.up = dummy.down = false;
  is.assign(n, vector<dir>(m));
  for (long long i = (long long)0; i <= (long long)n - 1; i++)
    for (long long j = (long long)0; j <= (long long)m - 1; j++) {
      char ch;
      cin >> ch;
      a[i][j] = (ch == '#');
      is[i][j].left = is[i][j].right = is[i][j].up = is[i][j].down = a[i][j];
      if (i > 0) is[i][j].up |= is[i - 1][j].up;
      if (j > 0) is[i][j].left |= is[i][j - 1].left;
      vis[i][j] = 0;
    }
  for (long long i = (long long)n - 1; i >= (long long)0; i--)
    for (long long j = (long long)m - 1; j >= (long long)0; j--) {
      if (i < n - 1) is[i][j].down |= is[i + 1][j].down;
      if (j < m - 1) is[i][j].right |= is[i][j + 1].right;
    }
  long long imp = 0;
  for (long long i = (long long)0; i <= (long long)n - 1; i++)
    for (long long j = (long long)0; j <= (long long)m - 1; j++)
      if (a[i][j] == 0) {
        if ((is[i][j].left && is[i][j].right) ||
            (is[i][j].up && is[i][j].down)) {
          imp = 1;
          break;
        }
        if (imp) break;
      }
  long long wrow = 0, wcol = 0;
  for (long long i = (long long)0; i <= (long long)n - 1; i++)
    if (is[i][0].right == false) wrow++;
  for (long long j = (long long)0; j <= (long long)m - 1; j++)
    if (is[0][j].down == false) wcol++;
  if (wrow + wcol > 0 && (wcol == 0 || wrow == 0)) imp = 1;
  if (imp) {
    cout << -1;
    return 0;
  }
  long long ans = 0;
  for (long long i = (long long)0; i <= (long long)n - 1; i++)
    for (long long j = (long long)0; j <= (long long)m - 1; j++)
      if (a[i][j] && !vis[i][j]) {
        dfs(i, j);
        ans++;
      }
  cout << ans;
  return 0;
}
