#include <iostream>
#include <algorithm>
using namespace std;

int m, n;
int dfs(int b[100][100], int y, int x){
	int a[100][100];
	for(int i = 0;i < 100;i++)
	for(int j = 0;j < 100;j++)a[i][j] = b[i][j];
	if(!a[y][x])return 0;
	int ans = a[y][x] = 0;
	if(a[y-1][x])ans = max(ans, dfs(a, y-1, x));
	if(a[y+1][x])ans = max(ans, dfs(a, y+1, x));
	if(a[y][x-1])ans = max(ans, dfs(a, y, x-1));
	if(a[y][x+1])ans = max(ans, dfs(a, y, x+1));
	return ans+1;
}

int main(){
	int a[100][100];
	while(cin >> m >> n, m){
		fill((int*)a, (int*)(a+100), 0);
		for(int i = 1;i <= n;i++)
		for(int j = 1;j <= m;j++)cin >> a[i][j];
		
		int ans = 0;
		for(int i = 1;i <= n;i++)
		for(int j = 1;j <= m;j++)ans = max(ans, dfs(a, i, j));
		cout << ans << endl;
		//cout << ans << endl;
	}
	return 0;
}