fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let h: usize = sc.read();
    let w: usize = sc.read();
    let s: Vec<Vec<char>> = (0..h).map(|_| sc.chars()).collect();
    let n = h * w;
    let mut uf = UnionFind::new(n);
    for i in 0..h {
        for j in 0..w {
            let id = i * w + j;
            if i + 1 < h && s[i][j] != s[i + 1][j] {
                let next = (i + 1) * w + j;
                uf.unite(id, next);
            }
            if j + 1 < w && s[i][j] != s[i][j + 1] {
                let next = i * w + j + 1;
                uf.unite(id, next);
            }
        }
    }

    let mut black = vec![0; n];
    let mut white = vec![0; n];
    for i in 0..h {
        for j in 0..w {
            let id = i * w + j;
            let root = uf.find(id);
            if s[i][j] == '#' {
                black[root] += 1;
            } else {
                white[root] += 1;
            }
        }
    }

    let mut used = vec![false; n];
    let mut ans: u64 = 0;
    for i in 0..h {
        for j in 0..w {
            let id = i * w + j;
            let root = uf.find(id);
            if used[root] {
                continue;
            }
            ans += black[root] * white[root];
            used[root] = true;
        }
    }

    println!("{}", ans);
}

pub struct UnionFind {
    parent: Vec<usize>,
    sizes: Vec<usize>,
    size: usize,
}

impl UnionFind {
    pub fn new(n: usize) -> UnionFind {
        UnionFind {
            parent: (0..n).map(|i| i).collect::<Vec<usize>>(),
            sizes: vec![1; n],
            size: n,
        }
    }

    pub fn find(&mut self, x: usize) -> usize {
        if x == self.parent[x] {
            x
        } else {
            let px = self.parent[x];
            self.parent[x] = self.find(px);
            self.parent[x]
        }
    }

    pub fn unite(&mut self, x: usize, y: usize) -> bool {
        let parent_x = self.find(x);
        let parent_y = self.find(y);
        if parent_x == parent_y {
            return false;
        }

        let (large, small) = if self.sizes[parent_x] < self.sizes[parent_y] {
            (parent_y, parent_x)
        } else {
            (parent_x, parent_y)
        };

        self.parent[small] = large;
        self.sizes[large] += self.sizes[small];
        self.sizes[small] = 0;
        self.size -= 1;
        return true;
    }
}
pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 12540