using namespace std ;
int n , m ;
int pd [99] [99] ;
char a [99] [99] ;
void dick ( int x , int y )
{
if ( pd [x + 1] [y] )
{
pd [x + 1] [y] = 0 ;
dick ( x + 1 , y ) ;
}
if ( pd [x - 1] [y] )
{
pd [x - 1] [y] = 0 ;
dick ( x - 1 , y ) ;
}
if ( pd [x - 1] [y] )
{
pd [x] [y - 1] = 0 ;
dick ( x , y - 1 ) ;
}
if ( pd [x] [y + 1] )
{
pd [x] [y + 1] = 0 ;
dick ( x , y + 1 ) ;
}
}
int main ()
{
cin >> n >> m ;
for ( int i = 1 ; i <= n ; ++i )
{
for ( int j = 1 ; j <= m ; ++j )
{
cin >> a [i] [j] ;
if ( a [i] [j] != '0')
{
pd [i] [j] = 1 ;
}
}
}
int ans = 0;
for ( int i = 1 ; i <= n ; ++i )
{
for ( int j = 1 ; j <= m ; ++j )
{
if ( pd [i] [j] ){
dick ( i , j );
++ans;
}
}
}
cout << ans ;
return 0 ;
}
/*
4 10
0234500067
1034560500
2045600671
0000000089
*/