#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;

typedef pair<int,int> Pa;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

int func(int a[91][91], bool vis[91][91], int s, int t, int h, int w, int c)
{
	int u = c;
	
	for(int i = 0; i < 4; i++){
		int y = s+dy[i], x = t+dx[i];
		if(0 <= y && y < h && 0 <= x && x < w){
			if(a[y][x] == 1 && vis[y][x]){
				vis[s][t] = false;
				u = max(u, func(a, vis, y, x, h, w, c+1));
				vis[s][t] = true;
			}
		}
	}
	
	return u;
}

int main()
{
	int a[91][91], w, h, t;
	bool vis[91][91];
	queue<Pa> que;
	
	while(1){
		cin >> w >> h;
		if(w == 0 && h == 0){
			break;
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin >> a[i][j];
				if(a[i][j] == 1){
					que.push(Pa(i,j));
				}
			}
		}
		
		t = 0;
		while(!que.empty()){
			Pa p = que.front();
			que.pop();
			fill(&vis[0][0], &vis[h][w], true);
			t = max(t, func(a, vis, p.first, p.second, h, w, 1));
		}
		cout << t << endl;
	}
	
	return 0;
}