#include <iostream>
#include <bitset>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;

bitset<92> map[92];
int W,H;
int ans;
int dx[] = {1,-1,0,0}, dy[] = {0,0,-1,1};

void saiki(int x , int y , int step)
{
	
	for(int i = 0; i < 4; i++){
		int nx = x+dx[i], ny = y+dy[i];

		if(map[ny][nx]){
			map[ny][nx] = 0;
			saiki(nx,ny,step+1);
			map[ny][nx] = 1;
		}
	}
	
	ans = max(ans,step);
}


int main(void)
{

	while(cin >> W >> H, W|H){
		int in;
		ans = 0;

		for(int i = 1; i <= H; i++){
			map[i] = 0;
			for(int j = 1; j <= W; j++){
				cin >> in;
				map[i][j] = in == 1;
			}
		}

		for(int i = 1; i <= H; i++){
			for(int j = 1; j <= W; j++){
				if(map[i][j]){
					saiki(j,i,0);
				}
			}
		}

		cout <<ans<<endl;
	}

	return 0;
}