#include<stdio.h>

int n,m,ans,lake[100][100];
int x[4] = {0,1,0,-1},y[4] = {-1,0,1,0};

void func(int i,int j,int c){
	lake[i][j] = 0;
	if(c > ans)ans=c;
	
	for(int k = 0;k < 4; k++)if(lake[i+x[k]][j+y[k]] && i+x[k] >= 0 && i+x[k] < n && j+y[k] >= 0  && j+y[k] < m)	func(i+x[k],j+y[k],c+1);
	lake[i][j] = 1;
}

int main(void){
	while(scanf("%d%d", &m, &n) && n && m){
		for(int i = 0; i < n; i++)for(int j = 0; j < m; j++)scanf("%d", &lake[i][j]);
		for(int i = 0; i < n; i++)for(int j = 0; j < m; j++)if(lake[i][j])func(i,j,1);
		
		ans = !printf("%d\n",ans);
	}
	return 0;
}