#include <bits/stdc++.h>
using namespace std;
void test() { cerr << "\n"; }
template <typename T, typename... Args>
void test(T x, Args... args) {
  cerr << "> " << x << " ";
  test(args...);
}
const long long mod = 1e9 + 7;
const int maxn = 1e5 + 9;
const int inf = 0x3f3f3f3f;
long long rd() {
  long long ans = 0;
  char last = ' ', ch = getchar();
  while (!(ch >= '0' && ch <= '9')) last = ch, ch = getchar();
  while (ch >= '0' && ch <= '9') ans = ans * 10 + ch - '0', ch = getchar();
  if (last == '-') ans = -ans;
  return ans;
}
int n, m;
char x[1009][1009];
const int di[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
bool vis[1009][1009];
void dfs(int i, int j) {
  vis[i][j] = 1;
  for (int _ = (int)(0); _ <= (int)(3); _++) {
    int I = i + di[_][0];
    int J = j + di[_][1];
    if (I < 1 || I > n || J < 1 || J > m || x[I][J] != '#' || vis[I][J])
      continue;
    dfs(I, J);
  }
}
int main() {
  n = rd(), m = rd();
  for (int i = (int)(1); i <= (int)(n); i++) {
    scanf("%s", x[i] + 1);
  }
  int emp_line = 0, emp_col = 0;
  bool cant = 0;
  for (int i = (int)(1); i <= (int)(n); i++) {
    int bi = -1, en = -1;
    for (int j = (int)(1); j <= (int)(m); j++) {
      if (x[i][j] == '#') {
        bi = j;
        break;
      }
    }
    if (bi == -1) {
      emp_line++;
    } else {
      for (int j = (int)(m); j >= (int)(1); j--) {
        if (x[i][j] == '#') {
          en = j;
          break;
        }
      }
      for (int j = (int)(bi); j <= (int)(en); j++) {
        if (x[i][j] != '#') {
          cant = 1;
          break;
        }
      }
      if (cant) break;
    }
  }
  if (cant) {
    puts("-1");
    return 0;
  }
  for (int j = (int)(1); j <= (int)(m); j++) {
    int bi = -1, en = -1;
    for (int i = (int)(1); i <= (int)(n); i++) {
      if (x[i][j] == '#') {
        bi = i;
        break;
      }
    }
    if (bi == -1) {
      emp_col++;
    } else {
      for (int i = (int)(n); i >= (int)(1); i--) {
        if (x[i][j] == '#') {
          en = i;
          break;
        }
      }
      for (int i = (int)(bi); i <= (int)(en); i++) {
        if (x[i][j] != '#') {
          cant = 1;
          break;
        }
      }
      if (cant) break;
    }
  }
  if (cant) {
    puts("-1");
    return 0;
  }
  if (emp_col && !emp_line) {
    puts("-1");
    return 0;
  }
  if (!emp_col && emp_line) {
    puts("-1");
    return 0;
  }
  int ans = 0;
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(1); j <= (int)(m); j++) {
      if (x[i][j] == '#' && !vis[i][j]) {
        dfs(i, j);
        ans++;
      }
    }
  printf("%d\n", ans);
  return 0;
}
