#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
bool mp[1005][1005];
int ans, n, m;
void dfs(int x, int y) {
  mp[x][y] = 0;
  for (int l = 0; l < 4; l++) {
    int i = x + dx[l], j = y + dy[l];
    if (!mp[i][j]) continue;
    dfs(i, j);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  char a;
  for (int i = 1; i <= n; i++) {
    getchar();
    for (int j = 1; j <= m; j++) {
      a = getchar();
      mp[i][j] = (a == '#');
    }
  }
  bool l1 = 0, l2 = 0, q;
  for (int i = 1; i <= n; i++) {
    q = 0;
    for (int j = 1; j <= m; j++)
      if (mp[i][j] && (!mp[i][j - 1])) {
        if (q) {
          printf("-1");
          return 0;
        } else
          q = 1;
      }
    if (!q) l1 = 1;
  }
  for (int j = 1; j <= m; j++) {
    q = 0;
    for (int i = 1; i <= n; i++)
      if (mp[i][j] && (!mp[i - 1][j])) {
        if (q) {
          printf("-1");
          return 0;
        } else
          q = 1;
      }
    if (!q) l2 = 1;
  }
  if (l1 ^ l2) {
    printf("-1");
    return 0;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (mp[i][j]) {
        ans++;
        dfs(i, j);
      }
  printf("%d", ans);
  return 0;
}
