#include<cstdio>
#include<algorithm>

int land[100][100];
int max_num;

using namespace std;

void saiki(int x,int y,int step);//xとyでjoi太郎君の場所を保存

int main(void)
{
	int tate,yoko;
	while(scanf("%d%d",&yoko,&tate))
	{
		if(tate == 0 && yoko == 0) break;
		for(int i = 0;i < tate;i++)
		{
			for(int j = 0;j < yoko;j++)
			{
				scanf("%d",&land[i][j]);
			}
		}
		for(int i = 0;i < tate;i++)
		{
			for(int j = 0;j < yoko;j++)
			{
				if(land[i][j] == 1)
				{
					saiki(j,i,1);
				}
			}
		}
		printf("%d\n",max_num);
		max_num = 0;
	}
	return 0;
}

void saiki(int x,int y,int step)
{
	static int flag[100][100] = {{0}};
	flag[y][x] = 1;
	
	if(y != 0 && land[y-1][x] == 1 && flag[y-1][x] == 0)
	{
		saiki(x,y-1,step+1);
	}
	

	if(x != 0 && land[y][x-1] == 1 && flag[y][x-1] == 0)
	{
		saiki(x-1,y,step+1);
	}

	if(land[y+1][x] == 1 && flag[y+1][x] == 0)
	{
		saiki(x,y+1,step+1);
	}

	if(land[y][x+1] == 1 && flag[y][x+1] == 0)
	{
		saiki(x + 1,y,step+1);
	}

	flag[y][x] = 0;
	if(step > max_num) max_num = step;
	return;
}