#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
int ans=0,a[1001][1001],d[8]={-1,0,1,0,0,1,0,-1},n,m;
queue<int> Q1;
queue<int> Q2;
void bfs(int x,int y)
{
int xx,yy;
a[x][y]=0;Q1.push(x);Q2.push(y);
ans++;
while (!Q1.empty())
{
for (int i=0;i<=3;i++)
{
xx=Q1.front()+d[i];yy=Q2.front()+d[i+4];
if ((xx>=0)&&(xx<n)&&(yy>=0)&&(yy<m)&&(a[xx][yy]))
{
Q1.push(xx);Q2.push(yy);a[xx][yy]=0;
}
}
Q1.pop();Q2.pop();
}
}
int main()
{
char ch;
int k,l;
freopen("p1451.in","r",stdin);
freopen("p1451.out","w",stdout);
scanf("%d%d",&n,&m);
for (int k=0;k<n;k++)
for (int l=0;l<m;l++)
{
scanf("%c",&ch);
if (ch-'0'>=1 && ch-'0'<=9) a[k][l]=1;else a[k][l]=0;
}
for (int k=0;k<n;k++)
for (int l=0;l<m;l++) if (a[k][l]) bfs(k,l);
printf("%d",ans);
}
#include<cstdio>
#include<queue>
using namespace std;
int ans=0,a[1001][1001],d[8]={-1,0,1,0,0,1,0,-1},n,m;
queue<int> Q1;
queue<int> Q2;
void bfs(int x,int y)
{
int xx,yy;
a[x][y]=0;Q1.push(x);Q2.push(y);
ans++;
while (!Q1.empty())
{
for (int i=0;i<=3;i++)
{
xx=Q1.front()+d[i];yy=Q2.front()+d[i+4];
if ((xx>=0)&&(xx<n)&&(yy>=0)&&(yy<m)&&(a[xx][yy]))
{
Q1.push(xx);Q2.push(yy);a[xx][yy]=0;
}
}
Q1.pop();Q2.pop();
}
}
int main()
{
char ch;
int k,l;
freopen("p1451.in","r",stdin);
freopen("p1451.out","w",stdout);
scanf("%d%d",&n,&m);
for (int k=0;k<n;k++)
for (int l=0;l<m;l++)
{
scanf("%c",&ch);
if (ch-'0'>=1 && ch-'0'<=9) a[k][l]=1;else a[k][l]=0;
}
for (int k=0;k<n;k++)
for (int l=0;l<m;l++) if (a[k][l]) bfs(k,l);
printf("%d",ans);
}