#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
const int MAXM = 1000005;
const int MOD = 1000000007;
const int MAMOD = 998244353;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double EPS = 1e-8;
char G[MAXN][MAXN];
int vis[MAXN][MAXN];
int r[MAXN], c[MAXN];
int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
int n, m, tot;
void bfs(int x, int y) {
  queue<pair<int, int>> q;
  q.push({x, y});
  vis[x][y] = tot;
  while (!q.empty()) {
    pair<int, int> now = q.front(), next;
    q.pop();
    for (int i = 0; i < 4; ++i) {
      next = {now.first + dir[i][0], now.second + dir[i][1]};
      if (next.first > 0 && next.first <= n && next.second > 0 &&
          next.second <= m && G[next.first][next.second] == '#' &&
          !vis[next.first][next.second]) {
        q.push(next);
        vis[next.first][next.second] = tot;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> G[i] + 1;
  bool ok = 1;
  int flag;
  for (int i = 1; i <= n; ++i) {
    flag = 0;
    for (int j = 1; j < m; ++j) {
      if (G[i][j] == '#' && G[i][j + 1] == '.' && flag == 0) flag = 1;
      if (G[i][j] == '.' && G[i][j + 1] == '#' && flag == 1) flag = 2;
    }
    if (flag == 2) ok = 0;
  }
  for (int i = 1; i <= m; ++i) {
    flag = 0;
    for (int j = 1; j < n; ++j) {
      if (G[j][i] == '#' && G[j + 1][i] == '.' && flag == 0) flag = 1;
      if (G[j][i] == '.' && G[j + 1][i] == '#' && flag == 1) flag = 2;
    }
    if (flag == 2) ok = 0;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (G[i][j] == '#') r[i] = 1;
  for (int i = 1; i <= m; ++i)
    for (int j = 1; j <= n; ++j)
      if (G[j][i] == '#') c[i] = 1;
  for (int i = 1; i <= n; ++i) {
    if (r[i] == 0) {
      flag = 0;
      for (int j = 1; j <= m; ++j)
        if (c[j] == 0) flag = 1;
      if (!flag) ok = 0;
    }
  }
  for (int i = 1; i <= m; ++i) {
    if (c[i] == 0) {
      flag = 0;
      for (int j = 1; j <= n; ++j)
        if (r[j] == 0) flag = 1;
      if (!flag) ok = 0;
    }
  }
  if (!ok)
    cout << "-1"
         << "\n";
  else {
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j)
        if (G[i][j] == '#' && !vis[i][j]) {
          tot++;
          bfs(i, j);
        }
    cout << tot << "\n";
  }
  return 0;
}
