// Arup Guha
// 4/10/2021
// Solution to 2021 USACO April Bronze Problem: Acowdemia III

import java.util.*;
import java.io.*;

public class c {

	public static int r;
	public static int c;
	public static char[][] grid;
	
	public static int[] DX = {-1,0,0,1};
	public static int[] DY = {0,-1,1,0};

	public static void main(String[] args) throws Exception {
	
		// Read in grid.
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tok = new StringTokenizer(stdin.readLine());
		r = Integer.parseInt(tok.nextToken());
		c = Integer.parseInt(tok.nextToken());
		grid = new char[r][];
		for (int i=0; i<r; i++)
			grid[i] = stdin.readLine().toCharArray();
			
		int res = 0;

		// Pairs of cows used.
		HashSet<Long> used = new HashSet<Long>();
		
		// Try to get a point for each grass.
		for (int i=0; i<r; i++) {
			for (int j=0; j<c; j++) {
			
				// Can't get a point.
				if (grid[i][j] != 'G') continue;
				
				// count # of adjacent cows, store their locations and the dx/dy index.
				int cnt = 0;
				ArrayList<Long> cList = new ArrayList<Long>();
				ArrayList<Integer> idx = new ArrayList<Integer>();
				for (int z=0; z<DX.length; z++) {
					int nx = i + DX[z];
					int ny = j + DY[z];
					if (!inbounds(nx,ny)) continue;
					if (grid[nx][ny] == 'C') {
						cnt++;
						cList.add((long)(nx*c+ny));
						idx.add(z);
					}
				}
				
				// Can't eat this grass.
				if (cnt < 2) continue;
				
				// Greedily match this grass.
				if (cnt == 2) {
					long code = cList.get(0)*(r*c) + cList.get(1);
					if (used.contains(code)) continue;
					res++;
					used.add(code);
				}
				
				// If we have 3 or 4 cows, we can always have a vertical or horizontal pair to grab.
				else {
					
					// Vertical.
					if (idx.contains(0) && idx.contains(3)) {
						long code = ((long)(c*i+j-c))*(r*c) +(c*i+j+c);
						res++;
						used.add(code);
					}
					
					// Horizontal.
					else if (idx.contains(1) && idx.contains(2)) {
						long code = ((long)(c*i+j-1))*(r*c) +(c*i+j+1);
						res++;
						used.add(code);
					}
				
				}
			}
		} // end for idx
		
		// Ta da!
		System.out.println(res);
	}
	
	public static boolean inbounds(int x, int y) {
		return x >= 0 && x < r && y >= 0 && y < c;
	}
}