#include <bits/stdc++.h>
using namespace std;
int n, m, t = 1;
char arr[1010][1010];
int pop[1010][1010];
void init() {
  for (int i = 0; i < n; ++i)
    for (int i2 = 0; i2 < m; ++i2) pop[i][i2] = 0;
}
void DFS(int x, int y) {
  pop[x][y] = t;
  if (x + 1 < n && !pop[x + 1][y] && arr[x + 1][y] == '#') DFS(x + 1, y);
  if (x - 1 >= 0 && !pop[x - 1][y] && arr[x - 1][y] == '#') DFS(x - 1, y);
  if (y + 1 < m && !pop[x][y + 1] && arr[x][y + 1] == '#') DFS(x, y + 1);
  if (y - 1 >= 0 && !pop[x][y - 1] && arr[x][y - 1] == '#') DFS(x, y - 1);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int i2 = 0; i2 < m; ++i2) cin >> arr[i][i2];
  int p = 1, freerow = 0, freecol = 0;
  for (int i = 0; i < n; ++i) {
    int gotR = 0, prev = '.';
    for (int i2 = 0; i2 < m; ++i2) {
      if (arr[i][i2] == '#' && prev == '.') {
        if (gotR)
          p = 0;
        else
          gotR = 1;
      }
      prev = arr[i][i2];
    }
    if (!gotR) freecol++;
  }
  for (int i2 = 0; i2 < m; ++i2) {
    int gotC = 0, prev = '.';
    for (int i = 0; i < n; ++i) {
      if (arr[i][i2] == '#' && prev == '.') {
        if (gotC)
          p = 0;
        else
          gotC = 1;
      }
      prev = arr[i][i2];
    }
    if (!gotC) freerow++;
  }
  if ((freecol && !freerow) || (!freecol && freerow)) p = 0;
  init();
  for (int i = 0; i < n; ++i)
    for (int i2 = 0; i2 < m; ++i2) {
      if (!pop[i][i2] && arr[i][i2] == '#') {
        DFS(i, i2);
        t++;
      }
    }
  if (!p)
    cout << -1 << endl;
  else
    cout << t - 1 << endl;
  return 0;
}
