#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[1005][1005];
bool vis[1005][1005];
bool row[1005], col[1005];
int D[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
vector<pair<int, int> > X, Y;
void dfs(int x, int y) {
  if (x < 1 || x > n || y < 1 || y > m || s[x][y] != '#') return;
  if (vis[x][y]) return;
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++) dfs(x + D[i][0], y + D[i][1]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '#') {
        X.emplace_back(make_pair(i, j));
        Y.emplace_back(make_pair(j, i));
      }
    }
  }
  sort((X).begin(), (X).end()), sort((Y).begin(), (Y).end());
  for (int i = 1; i < (int)(X).size(); i++) {
    if (X[i - 1].first == X[i].first && X[i - 1].second + 1 != X[i].second) {
      printf("-1\n");
      return 0;
    }
  }
  for (int i = 1; i < (int)(Y).size(); i++) {
    if (Y[i - 1].first == Y[i].first && Y[i - 1].second + 1 != Y[i].second) {
      printf("-1\n");
      return 0;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '#' && !vis[i][j]) {
        dfs(i, j);
        ans++;
        for (int i = 0; i < (int)(X).size(); i++) {
          row[X[i].first] = 1;
          col[X[i].second] = 1;
        }
      }
    }
  }
  int cnt_r = 0, cnt_c = 0;
  for (int i = 1; i <= n; i++) {
    if (!row[i]) cnt_r++;
  }
  for (int i = 1; i <= m; i++) {
    if (!col[i]) cnt_c++;
  }
  if ((cnt_r > 0 && cnt_c == 0) || (cnt_r == 0 && cnt_c > 0)) {
    printf("-1\n");
    return 0;
  }
  printf("%d\n", ans);
}
