#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;
vector<pair<int, int>> v[1000][1000];
bool visited[1000][1000];
int dfs(int y, int x) {
  visited[y][x] = true;
  int x0, y0;
  for (int i = 0; i < v[y][x].size(); ++i) {
    y0 = v[y][x][i].first;
    x0 = v[y][x][i].second;
    if (!visited[y0][x0]) {
      dfs(y0, x0);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  char c[n][m];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      visited[i][j] = false;
      cin >> c[i][j];
      if (c[i][j] == '#') {
        if (i - 1 >= 0) {
          if (c[i - 1][j] == '#') {
            v[i - 1][j].push_back({i, j});
            v[i][j].push_back({i - 1, j});
          }
        }
        if (j - 1 >= 0) {
          if (c[i][j - 1] == '#') {
            v[i][j - 1].push_back({i, j});
            v[i][j].push_back({i, j - 1});
          }
        }
      }
    }
  }
  int nr = 0, nc = 0;
  for (int i = 0; i < n; ++i) {
    bool hasWhite = false, hasBlack = false, hasBreak = false;
    ;
    for (int j = 0; j < m; ++j) {
      if (c[i][j] == '.') {
        hasWhite = true;
        if (hasBlack) {
          hasBreak = true;
        }
      }
      if (c[i][j] == '#') {
        hasBlack = true;
        if (hasBreak) {
          cout << -1;
          return 0;
        }
      }
    }
    if (!hasBlack) {
      nr++;
    }
  }
  for (int j = 0; j < m; ++j) {
    bool hasWhite = false, hasBlack = false, hasBreak = false;
    for (int i = 0; i < n; ++i) {
      if (c[i][j] == '.') {
        hasWhite = true;
        if (hasBlack) {
          hasBreak = true;
        }
      }
      if (c[i][j] == '#') {
        hasBlack = true;
        if (hasBreak) {
          cout << -1;
          return 0;
        }
      }
    }
    if (!hasBlack) {
      nc++;
    }
  }
  if ((nr > 0) != (nc > 0)) {
    cout << -1;
    return 0;
  }
  lli ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (c[i][j] == '#' && !visited[i][j]) {
        dfs(i, j);
        ans++;
      }
    }
  }
  cout << ans;
  return 0;
}
