import java.io.*;
import java.math.BigInteger;
import java.util.*;

/*
procrastinating
*/

public class Main {

    static FastReader in;
    static PrintWriter out;
    static Random rand = new Random();
    static final int INF = (int) (1e9 + 10);
    static final int MOD = (int) (998244353);

    static int n, m;
    static char[][] color;
    static boolean[][] vis;
    static int[][] dirs = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};

    static void dfs(int i, int j) {
        for (int[] d : dirs) {
            int i1 = i + d[0], j1 = j + d[1];
            if (i1 >= 0 && i1 < n && j1 >= 0 && j1 < m && color[i1][j1] == '#' && !vis[i1][j1]) {
                vis[i1][j1] = true;
                dfs(i1, j1);
            }
        }
    }

    static void solve() {
        n = in.nextInt();
        m = in.nextInt();

        color = new char[n][];
        for (int i = 0; i < n; i++)
            color[i] = in.next().toCharArray();

        vis = new boolean[n][m];
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (color[i][j] == '#' && !vis[i][j]) {
                    dfs(i, j);
                    cnt++;
                }
            }
        }

        boolean[][] rowPre = new boolean[n][m];
        boolean[][] rowSuf = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            rowPre[i][0] = color[i][0] == '#';
            for (int j = 1; j < m; j++) {
                rowPre[i][j] = rowPre[i][j - 1] | (color[i][j] == '#');
            }
            rowSuf[i][m - 1] = color[i][m - 1] == '#';
            for (int j = m - 2; j >= 0; j--) {
                rowSuf[i][j] = rowSuf[i][j + 1] | (color[i][j] == '#');
            }
        }

        boolean[][] colPre = new boolean[n][m];
        boolean[][] colSuf = new boolean[n][m];
        for (int j = 0; j < m; j++) {
            colPre[0][j] = color[0][j] == '#';
            for (int i = 1; i < n; i++) {
                colPre[i][j] = colPre[i - 1][j] | (color[i][j] == '#');
            }
            colSuf[n - 1][j] = color[n - 1][j] == '#';
            for (int i = n - 2; i >= 0; i--) {
                colSuf[i][j] = colSuf[i + 1][j] | (color[i][j] == '#');
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (color[i][j] == '.' && j - 1 >= 0 && j + 1 < m && rowPre[i][j] && rowSuf[i][j]) {
                    out.println(-1);
                    return;
                }
                if (color[i][j] == '.' && i - 1 >= 0 && i + 1 < n && colPre[i][j] && colSuf[i][j]) {
                    out.println(-1);
                    return;
                }
            }
        }

        boolean[] rowGood = new boolean[n];
        boolean[] colGood = new boolean[m];
        for (int i = 0; i < n; i++) {
            if (rowSuf[i][0]) {
                rowGood[i] = true;
            } else {
                for (int j = 0; j < m; j++) {
                    if (!colSuf[0][j]) {
                        rowGood[i] = true;
                        colGood[j] = true;
                    }
                }
            }
        }
        for (int j = 0; j < m; j++) {
            if (colSuf[0][j]) {
                colGood[j] = true;
            } else {
                for (int i = 0; i < n; i++) {
                    if (!rowSuf[i][0]) {
                        rowGood[i] = true;
                        colGood[j] = true;
                    }
                }
            }
        }

        for (int i = 0; i < n; i++) {
            if (!rowGood[i]) {
                out.println(-1);
                return;
            }
        }
        for (int j = 0; j < m; j++) {
            if (!colGood[j]) {
                out.println(-1);
                return;
            }
        }

        out.println(cnt);

    }

    public static void main(String[] args) throws FileNotFoundException, InterruptedException {
        in = new FastReader(System.in);
//        in = new FastReader(new FileInputStream("sometext.txt"));
        out = new PrintWriter(System.out);
//        out = new PrintWriter(new FileOutputStream("output.txt"));


        Thread thread = new Thread(null, () -> {
            int tests = 1;
//            tests = in.nextInt();

            while (tests-- > 0) {
                solve();
            }
        }, "Go", 1 << 28);
        thread.start();
        thread.join();


//        out.flush();
        out.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        Integer nextInt() {
            return Integer.parseInt(next());
        }

        Long nextLong() {
            return Long.parseLong(next());
        }

        Double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }
}