#include<bits/stdc++.h>
using namespace std;
int b[101][101],n,m,xx,yy,head,tail,num=-1;
int dx[5]={0,-1,1,0,0};
int dy[5]={0,0,0,-1,1};
struct JF{
int x,y;
}YY[10001];
int main() {
cin>>n>>m;
char ch;
for (int i=1;i<=n;i++) {
for (int j=1;j<=m;j++) {
cin>>ch;
if (ch=='0') b[i][j]=0;
else b[i][j]=ch-'0';
}
}
for (int i=1;i<=n;i++) {
for (int j=1;i<=m;j++) {
if (b[i][j]==0) continue;
num++;
head=0,tail=1;
YY[1].x=i;
YY[1].y=j;
b[i][j]=0;
while (head<tail) {
head++;
for (int k=1;k<=4;k++) {
int xx=YY[head].x+dx[k];
int yy=YY[head].y+dy[k];
if (b[xx][yy]!=0) {
tail++;
b[xx][yy]=0;
YY[tail].x=xx;
YY[tail].y=yy;
}
}
}
}
}
cout<<num;
return 0;
}
样例能过但全RE