#include<cstdio>
#include<cstring>
using namespace std;

bool ice[92][92];
int max;
int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };
int m, n;

void solve(int x, int y, int cnt){
	if (cnt > max)max = cnt;
	for (int i = 0; i < 4; i++){
		int nx = x + dx[i], ny = y + dy[i];
		if (ice[nx][ny]){
			ice[nx][ny] = 0;
			solve(nx, ny, cnt + 1);
			ice[nx][ny] = 1;
		}
	}
}
int main(){
	while (scanf("%d%d", &m, &n), m){
		max = 0;
		memset(ice, 0, sizeof(ice));
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= m; j++){
				scanf("%d", &ice[j][i]);
			}
		}
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= m; j++){
				if (ice[j][i]){
					ice[j][i] = 0;
					solve(j, i, 1);
					ice[j][i] = 1;
				}
			}
		}
		printf("%d\n", max);
	}
	return 0;
}