#include <bits/stdc++.h>
using namespace std;
const int xp[] = {1, 0, -1, 0};
const int yp[] = {0, 1, 0, -1};
void scan(int &a) {
  char c = getchar();
  a = 0;
  while (c >= '0' && c <= '9') {
    a *= 10;
    a += c - '0';
    c = getchar();
  }
}
const int maxn = 1005;
int n, m;
bool l[maxn][maxn];
bool bio1[maxn], bio2[maxn];
bool bio[maxn][maxn];
void dfs(int x, int y) {
  bio[x][y] = 1;
  int xs, ys;
  for (int i = 0; i < 4; i++) {
    xs = x + xp[i];
    ys = y + yp[i];
    if (xs > -1 && ys > -1 && xs < n && ys < m && l[xs][ys] && !bio[xs][ys]) {
      dfs(xs, ys);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  scan(n);
  scan(m);
  char c;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      c = getchar();
      if (c == '#') {
        l[i][j] = 1;
      } else {
        l[i][j] = 0;
      }
    }
    getchar();
  }
  int xs, ys;
  int br;
  int broj;
  bool p = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (l[i][j]) {
        bio1[i] = 1;
        bio2[j] = 1;
        br = 0;
        for (int k = 0; k < 4; k++) {
          xs = i + xp[k];
          ys = j + yp[k];
          if (xs > -1 && ys > -1 && xs < n && ys < m && l[xs][ys]) {
            br++;
          }
        }
        if (br < 3) {
          broj = 0;
          for (int k = 0; k < m; k++) {
            if (l[i][k] && (!k || !l[i][k - 1])) {
              broj++;
            }
          }
          if (broj > 1) {
            cout << -1 << '\n';
            return 0;
          }
          broj = 0;
          for (int k = 0; k < n; k++) {
            if (l[k][j] && (!k || !l[k - 1][j])) {
              broj++;
            }
          }
          if (broj > 1) {
            cout << -1 << '\n';
            return 0;
          }
        }
      }
    }
  }
  bool red = 0, stup = 0;
  for (int i = 0; i < n; i++) {
    if (!bio1[i]) {
      red = 1;
    }
  }
  for (int i = 0; i < m; i++) {
    if (!bio2[i]) {
      stup = 1;
    }
  }
  if (red ^ stup) {
    cout << -1 << '\n';
    return 0;
  }
  int sol = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (l[i][j] && !bio[i][j]) {
        dfs(i, j);
        sol++;
      }
    }
  }
  cout << sol << '\n';
  return 0;
}
