#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const long long maxn = 1011;
long long a[maxn][maxn], p[maxn * maxn], r[maxn * maxn];
long long get_parent(long long v) {
  if (p[v] == v) return v;
  return p[v] = get_parent(p[v]);
}
void merge(long long aa, long long bb) {
  aa = get_parent(aa);
  bb = get_parent(bb);
  if (aa == bb) {
    return;
  }
  if (r[aa] < r[bb]) swap(aa, bb);
  p[bb] = aa;
  if (r[aa] == r[bb]) r[aa]++;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  long long cnt = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      p[i * m + j] = i * m + j;
      char ch;
      cin >> ch;
      if (ch == '#') a[i][j] = 1;
      cnt += a[i][j];
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (a[i][j] == 1) {
        if (i + 1 < n && a[i + 1][j] == 1) {
          merge(i * m + j, (i + 1) * m + j);
        }
        if (i - 1 >= 0 && a[i - 1][j] == 1) {
          merge(i * m + j, (i - 1) * m + j);
        }
        if (j + 1 < n && a[i][j + 1] == 1) {
          merge(i * m + j, (i)*m + j + 1);
        }
        if (j - 1 >= 0 && a[i][j - 1] == 1) {
          merge(i * m + j, (i)*m + j - 1);
        }
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      get_parent(i * m + j);
      if (a[i][j] == 1 && p[i * m + j] == i * m + j) {
        ans++;
      }
    }
  }
  long long cnt1 = 0, cnt2 = 0;
  for (long long i = 0; i < n; i++) {
    long long was = 0;
    for (long long j = 0; j < m; j++) {
      if (a[i][j] == 1) {
        if (was == 2 || m == 1 || n == 1) {
          ans = -1;
          break;
        }
        was = 1;
      } else if (was == 1) {
        was = 2;
      }
    }
    if (was == 0) {
      cnt1++;
    }
  }
  for (long long i = 0; i < m; i++) {
    long long was = 0;
    for (long long j = 0; j < n; j++) {
      if (a[j][i] == 1) {
        if (was == 2) {
          ans = -1;
          break;
        }
        was = 1;
      } else if (was == 1) {
        was = 2;
      }
    }
    if (was == 0) cnt2++;
  }
  if ((cnt1 || cnt2) && cnt1 * cnt2 == 0) ans = -1;
  if (((n == 1) || (m == 1)) && (cnt == n * m)) ans = 1;
  cout << ans << "\n";
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  solve();
  return 0;
}
