#include <bits/stdc++.h>
using namespace std;

const int N = 1e4 + 10, 
		  dx[4] = {0, 0, 1, -1},  // dx和dy可以让方向移动更变便捷 
		  dy[4] = {1, -1, 0, 0}; // 分别对应 向右(x,y+1) 向左(x,y-1) 向下(x+1,y) 向上(x-1,y)

struct sit
{
	int x, y;
};

int n, m, ans, a[N][N];
char c;

void bfs(int sx, int sy)
{
	queue <sit> q;
	q.push( {sx, sy} );
	
	while (q.size())
	{
		sit top = q.front(); 
		q.pop();
		a[top.x][top.y] = 0;
		
		for (int i = 0; i < 4; i++)
		{
			int xx = top.x + dx[i], yy = top.y + dy[i]; // (xx,yy)即可能可以去的点 
			if (xx >= 1 and xx <= n and yy >= 1 and yy <= m and a[xx][yy] != 0) // 判断(xx,yy)到底能不能去 条件:1.不越界 2.没去过/不连通,本题诗后者 
				q.push( {xx, yy} ); // 加入队列 
		}
	}
}

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> c, a[i][j] = c - '0';
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (a[i][j] > 0)
			{
				bfs(i, j); // bfs!把联通的都变成0,这样就不会重复搜索到同一个细胞。 
				ans++; // 一旦找到不为0的就++,因为bfs会把联通的都变成0,所以找到非0的点就一定是全新的细胞。 
			}
	cout << ans;
	
	return 0;
 }