#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
inline unsigned long long rnd() {
  return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;
}
const int N = 1005;
int n, m, ans, fa[N * N], f[N], g[N];
char ch[N][N];
inline int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }
void mer(int a, int b) {
  a = gf(a);
  b = gf(b);
  fa[a] = b;
}
inline int zb(int x, int y) { return (x - 1) * m + y; }
int main() {
  n = read(), m = read();
  for (int i = (int)(1); i <= (int)(n); i++) {
    scanf("%s", ch[i] + 1);
  }
  for (int i = (int)(1); i <= (int)(n * m); i++) fa[i] = i;
  for (int i = (int)(1); i <= (int)(n); i++) {
    for (int j = (int)(1); j <= (int)(m); j++) {
      if (ch[i][j] == '#') {
        if (ch[i - 1][j] == '#') mer(zb(i, j), zb(i - 1, j));
        if (ch[i][j - 1] == '#') mer(zb(i, j), zb(i, j - 1));
        f[i] = 1;
        g[j] = 1;
      }
    }
  }
  for (int i = (int)(1); i <= (int)(n * m); i++)
    if (fa[i] == i && ch[(i + m - 1) / m][i % m ? i % m : m] == '#') ans++;
  int ff = 0, gg = 0;
  for (int i = (int)(1); i <= (int)(n); i++)
    if (!f[i]) ff = 1;
  for (int j = (int)(1); j <= (int)(m); j++)
    if (!g[j]) gg = 1;
  if (ff + gg == 1) ans = -1;
  for (int i = (int)(1); i <= (int)(n); i++) {
    int jb = 0, dq = 0;
    for (int j = (int)(1); j <= (int)(m); j++)
      if (ch[i][j] == '#') {
        dq++;
      } else if (dq && !jb)
        jb = dq;
    if (jb != dq && jb) ans = -1;
  }
  for (int j = (int)(1); j <= (int)(m); j++) {
    int jb = 0, dq = 0;
    for (int i = (int)(1); i <= (int)(n); i++)
      if (ch[i][j] == '#') {
        dq++;
      } else if (dq && !jb)
        jb = dq;
    if (jb != dq && jb) ans = -1;
  }
  cout << ans << endl;
}
