#include <stdio.h>

#define N 50

static
int map[ N ][ N ];
static
int w, h;

int dfs (
  int x,
  int y
  )
{
  if ( x < 0 || x >= w
    || y < 0 || y >= h )    return ( 0 );
  if ( map[ x ][ y ] == 0 ) return ( 0 );

  map[ x ][ y ] = 0;
  dfs ( x - 1, y - 1 );
  dfs ( x - 1, y );
  dfs ( x - 1, y + 1 );
  dfs ( x, y - 1 );
  dfs ( x, y + 1 );
  dfs ( x + 1, y - 1 );
  dfs ( x + 1, y );
  dfs ( x + 1, y + 1 );

  return ( 1 );
}

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    int x, y;
    int res = 0;

    scanf ( "%d%d", &w, &h );
    if ( !( w | h ) ) break ;

    for ( y = 0; y < h; ++y )
    for ( x = 0; x < w; ++x )
    {
      scanf ( "%d", &map[ x ][ y ] );
    }

    for ( y = 0; y < h; ++y )
    for ( x = 0; x < w; ++x )
    {
      res += dfs ( x, y );
    }

    printf ( "%d\n", res );
  }

  return ( 0 );
}