#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 7;
int d[4][2] = {1, 0, 0, 1, 0, -1, -1, 0};
char mp[N][N];
bool mark[N][N];
int row[N];
int com[N];
int n, m;
void dfs(int x, int y) {
  mark[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    int x1 = x + d[i][1];
    int y1 = y + d[i][0];
    if (x1 <= n && x1 >= 1 && y1 <= m && y1 >= 1 && !mark[x1][y1] &&
        mp[x1][y1] == '#') {
      dfs(x1, y1);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%s", mp[i] + 1);
  bool flag = 0;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == '#') {
        row[i]++;
        com[j]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int tmp = 0;
    int pre;
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == '#') {
        if (tmp == 0) {
          pre = j;
        } else {
          if (j - pre != 1) {
            flag = 1;
          }
          pre = j;
        }
        tmp++;
      }
    }
    if (tmp == 0) {
      bool pos = 0;
      for (int k = 1; k <= m; k++) {
        if (com[k] == 0) {
          pos = 1;
        }
      }
      if (!pos) flag = 1;
    }
  }
  for (int i = 1; i <= m; i++) {
    int tmp = 0;
    int pre;
    for (int j = 1; j <= n; j++) {
      if (mp[j][i] == '#') {
        if (tmp == 0) {
          pre = j;
        } else {
          if (j - pre != 1) {
            flag = 1;
          }
          pre = j;
        }
        tmp++;
      }
    }
    if (tmp == 0) {
      bool pos = 0;
      for (int k = 1; k <= n; k++) {
        if (row[k] == 0) {
          pos = 1;
        }
      }
      if (!pos) flag = 1;
    }
  }
  if (flag) {
    puts("-1");
    return 0;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == '#' && !mark[i][j]) {
        dfs(i, j);
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
