#include <bits/stdc++.h>
using namespace std;
char c;
long long unsigned n, m, sym;
bool mp[1050][1050], wnt[1050][1050], mrx[1050], mry[1050], hax[1050],
    hay[1050];
inline void re(long long unsigned &x) {
  c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = (x * 10) + (c ^ 48);
    c = getchar();
  }
  return;
}
void dfs(const long long unsigned x, const long long unsigned y) {
  if (x < n && mp[x + 1][y] && !wnt[x + 1][y]) {
    wnt[x + 1][y] = true;
    dfs(x + 1, y);
  }
  if (y < m && mp[x][y + 1] && !wnt[x][y + 1]) {
    wnt[x][y + 1] = true;
    dfs(x, y + 1);
  }
  if (x > 1 && mp[x - 1][y] && !wnt[x - 1][y]) {
    wnt[x - 1][y] = true;
    dfs(x - 1, y);
  }
  if (y > 1 && mp[x][y - 1] && !wnt[x][y - 1]) {
    wnt[x][y - 1] = true;
    dfs(x, y - 1);
  }
  return;
}
signed main() {
  re(n);
  re(m);
  for (register long long unsigned i = 1; i <= n; ++i) {
    while (c != '.' && c != '#') c = getchar();
    sym = 0;
    for (register long long unsigned j = 1; j <= m; ++j) {
      if (c == '#') {
        hax[i] = mrx[i] = true;
        if (sym == 2) {
          printf("-1\n");
          return 0;
        } else if (sym == 0)
          sym = 1;
        mp[i][j] = true;
      } else {
        if (sym == 1) sym = 2;
        mp[i][j] = false;
      }
      c = getchar();
    }
  }
  for (register long long unsigned i = 1; i <= m; ++i) {
    sym = 0;
    for (register long long unsigned j = 1; j <= n; ++j) {
      if (mp[j][i]) {
        hay[i] = mry[i] = true;
        if (sym == 2) {
          printf("-1\n");
          return 0;
        } else if (sym == 0)
          sym = 1;
      } else {
        if (sym == 1) sym = 2;
      }
    }
  }
  for (register long long unsigned i = 1; i <= n; ++i)
    if (!hax[i]) {
      for (register long long unsigned j = 1; j <= m; ++j)
        if (!mry[j]) {
          hax[i] = hay[j] = true;
          break;
        }
      if (!hax[i]) {
        printf("-1\n");
        return 0;
      }
    }
  for (register long long unsigned i = 1; i <= m; ++i)
    if (!hay[i]) {
      for (register long long unsigned j = 1; j <= n; ++j)
        if (!mrx[j]) {
          hay[i] = hax[j] = true;
          break;
        }
      if (!hay[i]) {
        printf("-1\n");
        return 0;
      }
    }
  sym = 0;
  for (register long long unsigned i = 1; i <= n; ++i)
    for (register long long unsigned j = 1; j <= m; ++j)
      if (mp[i][j] && !wnt[i][j]) {
        ++sym;
        wnt[i][j] = true;
        dfs(i, j);
      }
  printf("%llu\n", sym);
  return 0;
}
