#include <bits/stdc++.h>
using namespace std;
int _[1005][1005], x[1005], y[1005], n, m;
int vis[1005][1005], dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
void dfs(int x, int y) {
  if (!_[x][y] || x < 1 || y < 1 || x > n || y > m || vis[x][y]) return;
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++) dfs(x + dx[i], y + dy[i]);
  return;
}
int ans, xx[1005], yy[1005];
int main() {
  register int i, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    for (getchar(), j = 1; j <= m; j++) _[i][j] = (getchar() == '#');
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if (!_[i][j - 1] && _[i][j] && x[i]++)
        return puts("-1"), 0;
      else if (!_[i - 1][j] && _[i][j] && y[j]++)
        return puts("-1"), 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if ((!x[i] && !y[j]) || _[i][j]) xx[i] = yy[j] = 1;
  for (i = 1; i <= n; i++)
    if (!xx[i]) return puts("-1"), 0;
  for (j = 1; j <= m; j++)
    if (!yy[j]) return puts("-1"), 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      if (!vis[i][j] && _[i][j]) dfs(i, j), ans++;
  printf("%d", ans);
  return 0;
}
