/*
  AOJ 1128
  Title:Square Carpets
  @kankichi573
*/
#include <stdio.h>
#define min(x,y) (((x)<(y))?(x):(y))
int panel[10][10];
int w,h;

void search_pos(int *y,int *x)
{
  int i,j;

  i=*y;j=*x;
  goto SEARCH;

  for(i=0;i<h;i++)
    for(j=0;j<w;j++)
      {
      SEARCH:
	if(panel[i][j])
	  {
	    *y=i;*x=j;
	    return;
	  }
      }
  *x=*y=-1;
}

int check_square(int y,int x,int *scr)
{
  int i,j,ret,c1[11],minwh;

  minwh=min(h-y,w-x);
  c1[1]=((panel[y][x]==1)?1:0);
  for(ret=2;ret<=minwh;ret++)
    {
      c1[ret]=0;
      for(i=0;i<ret;i++)
	for(j=0;j<ret;j++)
	  if(panel[y+i][x+j]==0)
	    {
	      //printf("** %d %d\n",y+j,x+i);
	      if(c1[ret-1])  // at least 1 scratched panel
		{
		  *scr=c1[ret-1];  //count of scratch panel
		  return(ret-1);
		}
	      else
		return(0);
	    }
	  else if(panel[y+i][x+j]==1)
	    c1[ret]++;
    }
  if(c1[ret-1])
    {
      *scr=c1[ret-1];
      return(minwh);
    }
  else
    {
      *scr=0;
      return(0);
    }
}


int search_biggest_square(int *yp,int *xp)
{
  int max_=0,siz,y,x,max_x,max_y,minwh,c1[11];
  int i,j,ret,scr,scrmax;

  x=y=scrmax=0;
  while(search_pos(&y,&x) , y!=-1)
    {
      ret=check_square(y,x,&scr);
      //printf("yxr=%d %d %d [%d]\n",y,x,ret,scr);
      if(ret>max_)
	{
	  max_=ret;
	  scrmax=scr;
	  max_y=y;max_x=x;
	}
      else if(ret==max_ && scr > scrmax)
	{
	  scrmax=scr;
	  max_y=y;max_x=x;
	}
      x++;
      if(x>=w)
	{
	  y++;
	  x=0;
	}
      if(y>=h)
	break;
    }
  *xp=max_x;
  *yp=max_y;
  return(max_);
}



void carpet_square(int y,int x,int size)
{
  int i,j;

    for(i=0;i<size;i++)
      for(j=0;j<size;j++)
	panel[y+i][x+j]=2;
}
void dump()
{
  int i,j;

    for(i=0;i<h;i++)
      {
	for(j=0;j<w;j++)
	  printf("%d",panel[i][j]);
	printf("\n");
      }
    printf("----------\n");
}
int solve()
{
  int ret=0,siz,y,x;
  
  y=x=0;
  while(siz=search_biggest_square(&y,&x))
    {
      //printf("csqsiz=%d yx=%d %d\n",siz,y,x);
      carpet_square(y,x,siz);
      ret++;
      //dump();

      x++;
      if(x>=w)
	{
	  x=0;
	  y++;
	}
      if(y>h)
	break;
    }
  return(ret);
}
main()
{
  int i,j,ret;

  while(scanf("%d %d",&w,&h) && (w||h))
    {
      for(i=0;i<h;i++)
	for(j=0;j<w;j++)
	  scanf("%d",&panel[i][j]);
      ret=solve();
      printf("%d\n",ret);
    }
  return(0);
}