import std.stdio;
import core.stdc.stdio;
import std.algorithm;

int n,m;
int[][] map;
int ans=0;

void DFS(int y,int x,int count){
	map[y][x] = 0;
	int[] dx=[0,-1,0,1];
	int[] dy=[-1,0,1,0];
	for(int k=0;k<4;k++){
		int ny = y+dy[k];
		int nx = x+dx[k];
		if(0<=ny&&ny<n&&0<=nx&&nx<m&&map[ny][nx] == 1)
			DFS(ny,nx,count+1);
	}
	map[y][x] = 1;
	ans = max(count,ans);
}

void main(){
	while(1){
		ans = 0;
		scanf("%d%d",&m,&n);
		if(m==0&&n==0)
			break;
		map = new int[][n];
		for(int i=0;i<n;i++){
			map[i] = new int[m];
			for(int j=0;j<m;j++){
				scanf("%d",&map[i][j]);
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(map[i][j] == 1)
					DFS(i,j,1);
			}
		}
		printf("%d\n",ans);
	}
}