#include <bits/stdc++.h>
using namespace std;
const int seed = 131;
const long long LLMAX = 2e18;
const int MOD = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 1e3 + 10;
const int hmod1 = 0x48E2DCE7;
const int hmod2 = 0x60000005;
inline long long sqr(long long x) { return x * x; }
inline int sqr(int x) { return x * x; }
inline double sqr(double x) { return x * x; }
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long exgcd(long long a, long long b, long long &x, long long &y) {
  long long d;
  (b == 0 ? (x = 1, y = 0, d = a)
          : (d = exgcd(b, a % b, y, x), y -= a / b * x));
  return d;
}
long long qpow(long long a, long long n) {
  long long sum = 1;
  while (n) {
    if (n & 1) sum = sum * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return sum;
}
inline int dcmp(double x) {
  if (fabs(x) < eps) return 0;
  return (x > 0 ? 1 : -1);
}
char s[MAXN][MAXN];
int n, m, f = 0, ans = 0;
int r[MAXN], c[MAXN], vis[MAXN][MAXN];
void dfs(int x, int y) {
  vis[x][y] = 1;
  if (x + 1 <= n && s[x + 1][y] == '#' && !vis[x + 1][y]) dfs(x + 1, y);
  if (x - 1 >= 1 && s[x - 1][y] == '#' && !vis[x - 1][y]) dfs(x - 1, y);
  if (y + 1 <= m && s[x][y + 1] == '#' && !vis[x][y + 1]) dfs(x, y + 1);
  if (y - 1 >= 1 && s[x][y - 1] == '#' && !vis[x][y - 1]) dfs(x, y - 1);
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> (s[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (s[i][j] == '#') {
        if (r[i] == 0 || r[i] == j - 1)
          r[i] = j;
        else
          f = 1;
        if (c[j] == 0 || c[j] == i - 1)
          c[j] = i;
        else
          f = 1;
      }
  for (int i = 1; i <= n; i++)
    if (!r[i])
      for (int j = 1; j <= m; j++)
        if (!c[j] || c[j] == 0x3f3f3f3f) r[i] = c[j] = 0x3f3f3f3f;
  for (int i = 1; i <= n; i++)
    if (!r[i]) f = 1;
  for (int i = 1; i <= m; i++)
    if (!c[i]) f = 1;
  if (f)
    cout << -1 << endl;
  else {
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++)
        if (s[i][j] == '#' && vis[i][j] == 0) dfs(i, j), ans++;
    cout << ans << endl;
  }
  return 0;
}
