
import java.awt.*;
import java.util.Scanner;
import java.util.Stack;

/**
 * Created by rkarumuru on 5/12/20
 **/
public class Monopoles {

  private static Scanner scanner = new Scanner(System.in);

  public static void main(String[] args) {

    int n = scanner.nextInt();
    int m = getInt();
    solve(n, m);

  }

  private static void solve(int n, int m) {
    int[][] a = new int[n][m];
    for (int i = 0; i < n; i++) {
      String[] split = scanner.nextLine().split("");
      for (int j = 0; j < m; j++) {
        a[i][j] = split[j].equals("#") ? 1 : 0;
      }
    }
    if (!isValid(a, n, m)) {
      System.out.println(-1);
      return;
    }
    int bc = 0;

    Stack<Point> s = new Stack<>();
    int cc = 2;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (a[i][j] == 1) {
          bc++;
          s.push(new Point(i, j));
          while (!s.isEmpty()) {
            Point p = s.pop();
            int x1 = (int) p.getX();
            int y1 = (int) p.getY();
            a[x1][y1] = cc;
            if (x1 - 1 >= 0 && a[x1 - 1][y1] == 1) s.push(new Point(x1 - 1, y1));
            if (x1 + 1 < n && a[x1 + 1][y1] == 1) s.push(new Point(x1 + 1, y1));
            if (y1 - 1 >= 0 && a[x1][y1 - 1] == 1) s.push(new Point(x1, y1 - 1));
            if (y1 + 1 < m && a[x1][y1 + 1] == 1) s.push(new Point(x1, y1 + 1));
          }
        }
      }
    }
    System.out.println(bc);
  }

  private static boolean isValid(int[][] a, int n, int m) {
    if (n == 1) {
      boolean b = false;
      boolean w = false;
      for (int i = 0; i < m; i++) {
        if (a[0][i] == 1) {
          b = true;
          if (w == true) {
            return false;
          }
        } else {
          w = true;
          if (b) return false;
        }
      }

    } else if (m == 1) {
      boolean b = false;
      boolean w = false;
      for (int i = 0; i < n; i++) {
        if (a[i][0] == 1) {
          b = true;
          if (w == true) {
            return false;
          }
        } else {
          w = true;
          if (b) return false;
        }
      }

    } else {
      for (int i = 0; i < n; i++) {
        boolean black = false;
        boolean blackToWhite = false;
        for (int j = 0; j < m; j++) {
          if (a[i][j] == 1) {
            if (blackToWhite) {
              return false;
            }
            black = true;
          } else if (black == true) {
            blackToWhite = true;
          }
        }
      }
      for (int j = 0; j < m; j++) {
        boolean black = false;
        boolean blackToWhite = false;
        for (int i = 0; i < n; i++) {
          if (a[i][j] == 1) {
            if (blackToWhite) {
              return false;
            }
            black = true;
          } else {
            if (black == true) {
              blackToWhite = true;
            }
          }
        }
      }
    }

    //if one row is zero. Ensure atleast one column is 0
    boolean zr = false;
    boolean zc = false;
    outer:
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (a[i][j] == 1) {
          continue outer;
        }
      }
      zr = true;
    }


      //ensure atleast one column is zero;

      outer:
      for (int j = 0; j < m; j++) {
        for (int i = 0; i < n; i++) {
          if (a[i][j] == 1) {
            continue outer;
          }
        }
        zc = true;
      }

   return !(zc ^ zr);

  }

  public static int getInt() {
    return Integer.parseInt(scanner.nextLine().trim());
  }

  public static String getString() {
    return scanner.nextLine().trim();
  }

  public static double getDouble() {
    return Double.parseDouble(scanner.nextLine());
  }

  public static long getlong() {
    return Long.parseLong(scanner.nextLine());
  }
}
