using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        StreamReader read = new StreamReader(new FileStream("video.in", FileMode.Open));
        StreamWriter write = new StreamWriter(new FileStream("video.out", FileMode.Create));
        int[] nm = read.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        int[,] a = new int[nm[0], nm[1]];
        for (int i = 0; i < nm[0]; i ++)
        {
            string g = read.ReadLine();
            for (int j = 0; j < nm[1]; j++)
                a[i, j] = Convert.ToInt32(g[j]);
        }
        int ans = 0;
        for (int i = 0; i < nm[0] - 1; i++)
            for (int j = 0; j < nm[1] - 1; j++)
            {
                int eq = 0;
                for (int k = -1; k < 1; k++)
                    for (int l = -1; l < 1; l++)
                    {
                        int ind1 = i + k, ind2 = j + l;
                        if (ind1 < 0)
                            ind1 = nm[0] - 1;
                        if (ind2 < 0)
                            ind2 = nm[1] - 1;
                        if (a[i, j] == a[ind1, ind2])
                            eq++;
                    }
                if (eq == 4)
                    ans++;
            }
        write.WriteLine(ans);
        read.Close();
        write.Close();
    }
}