#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#if 0
#include <iostream>
#else
#include <fstream>
ifstream cin("video.in");
ofstream cout("video.out");
#endif
vector<vector<int> > mp;


int n, m;

int main()
{
	cin >> n >> m;
	mp.resize(2 * n + 2);
	for (int i = 0; i < 2 * n + 2; ++i)
	{
		mp[i].resize(2 * m + 2, 0);
	}
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			char t;
			cin >> t;
			mp[i][j] = (t - '0');
		}
	}

	for (int i = 0; i < n; ++i)
	{
		int l = mp[i][0];
		bool f = false;
		for (int j = 0; j < m; ++j)
		{
			if (l != mp[i][j]) { f = true; break; };
			mp[i][j + m] = l;
		}
	//	if (!f) for (int j = 0; j < m; ++j) mp[i][j + m] = 0;
	}
	
	for (int j = 0; j < m; ++j)
	{
		int l = mp[0][j];
		bool f = false;
		for (int i = 0; i < n; ++i)
		{
			if (mp[i][j] != l) { f = true; break; };
			mp[i + n][j] = l;
		}
		//if (!f) for (int i = 0; i < n; ++i) mp[i + n][j] = 0;
	}
/*
	for (int i = 0; i < 2 * n + 2; ++i)
	{
		for (int j = 0; j < 2 * m + 2; ++j)
		{
			cout << mp[i][j] << " ";
		}
		cout << endl;
	}
*/
	int ans = 0;
	
	int l = 2 * n - 1;

	for (int i = 0; i < 2 * n - 1; ++i)
	{
		l = 2 * n - 1;
		for (int j = 0; j < 2 * m - 1; ++j)
		{
			if (mp[i][j] == mp[i + 1][j])
			if (mp[i][j + 1] == mp[i + 1][j])
			if (mp[i + 1][j + 1] == mp[i + 1][j])
			if (mp[i][j] != 0)
			{
				ans++;
				l-=2;
			}
		}
	}

	cout << ans;
	
	return 0;	
}
