#include <bits/stdc++.h>
using namespace std;
char mp[1005][1005];
int l[1005][1005], r[1005][1005], fl[1005], fr[1005];
int vis[1005][1005];
int n, m, tot;
void dfs(int x, int y) {
  vis[x][y] = tot;
  if (x > 1 && l[x - 1][y] && !vis[x - 1][y]) dfs(x - 1, y);
  if (x < n && l[n][y] - l[x][y] && !vis[x + 1][y]) dfs(x + 1, y);
  if (y > 1 && r[x][y - 1] && !vis[x][y - 1]) dfs(x, y - 1);
  if (y < m && r[x][m] - r[x][y] && !vis[x][y + 1]) dfs(x, y + 1);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", mp[i] + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      r[i][j] = r[i][j - 1];
      l[i][j] = l[i - 1][j];
      if (mp[i][j] == '#') {
        fr[i] = 1;
        fl[j] = 1;
        l[i][j]++, r[i][j]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      if (mp[i][j] == '#' && !vis[i][j]) {
        tot++;
        dfs(i, j);
      }
  }
  int f = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == '.' && vis[i][j]) f = 0;
    }
  }
  int tn = n, tm = m;
  for (int i = 1; i <= n; i++)
    if (fr[i]) tn--;
  for (int i = 1; i <= m; i++)
    if (fl[i]) tm--;
  if (tn == 0 && tm == 0)
    ;
  else if (tn == 0 || tm == 0)
    f = 0;
  if (f)
    printf("%d", tot);
  else
    printf("-1");
}
