#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
char ma[1005][1005];
int vish[1005];
int visl[1005];
int zh[1005];
int n, m;
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
void dfs(int x, int y) {
  ma[x][y] = '.';
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (nx >= 0 && nx < n && ny >= 0 && ny < m && ma[nx][ny] == '#')
      dfs(nx, ny);
  }
}
int main() {
  int T;
  while (cin >> n >> m) {
    memset(vish, 0, sizeof(vish));
    memset(visl, 0, sizeof(visl));
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      cin >> ma[i];
      for (int j = 0; j < m; j++) {
        if (ma[i][j] == '#') {
          vish[i] = 1;
          visl[j] = 1;
          cnt++;
        }
      }
    }
    int flag = 1;
    for (int i = 0; i < n && flag; i++) {
      string str;
      str.push_back(ma[i][0]);
      for (int j = 1; j < m; j++) {
        if (ma[i][j] != ma[i][j - 1]) str.push_back(ma[i][j]);
      }
      if (str.length() > 3 || str == "#.#") {
        flag = 0;
      }
    }
    for (int j = 0; j < m && flag; j++) {
      string str;
      str.push_back(ma[0][j]);
      for (int i = 1; i < n; i++) {
        if (ma[i][j] != ma[i - 1][j]) str.push_back(ma[i][j]);
      }
      if (str.length() > 3 || str == "#.#") {
        flag = 0;
      }
    }
    int kh = 0;
    int kl = 0;
    for (int i = 0; i < n; i++)
      if (vish[i] == 0) kh++;
    for (int i = 0; i < m; i++)
      if (visl[i] == 0) kl++;
    if (flag && ((kh == 0 && kl == 0) || (kh != 0 && kl != 0))) {
      int ret = 0;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (ma[i][j] == '#') {
            ret++;
            dfs(i, j);
          }
        }
      }
      cout << ret << endl;
    } else
      cout << -1 << endl;
  }
}
