// Arup Guha
// 2/21/2015 (written in contest)
// Solution to 2015 February USACO Bronze Problem: Cow Hopscotch

import java.util.*;
import java.io.*;

public class hopscotch {

	public static void main(String[] args) throws Exception {

		Scanner stdin = new Scanner(new File("hopscotch.in"));
		FileWriter fout = new FileWriter(new File("hopscotch.out"));

        // Read in the grid.
		int r = stdin.nextInt();
		int c = stdin.nextInt();
		char[][] grid = new char[r][];
		for (int i=0; i<r; i++)
			grid[i] = stdin.next().toCharArray();

        // Set up the DP.
		long[][] dp = new long[r][c];
		dp[0][0] = 1;
		for (int i=0; i<r; i++) {
			for (int j=0; j<c; j++) {

                // Try all possible movements and add into the total.
				for (int dx=1; i+dx<r; dx++)
					for (int dy=1; j+dy<c; dy++)
						if (grid[i][j] != grid[i+dx][j+dy])
							dp[i+dx][j+dy] += dp[i][j];
			}
		}

		// Here is our result.
		fout.write(dp[r-1][c-1]+"\n");

		stdin.close();
		fout.close();
	}
}
