#include<bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int input() {
	int r;
	scanf("%lld", &r);
	return r;
}
int a[100][100];
int f(int i, int j) {
	if (a[i][j] == 0)return 0;
	int r = 0;
	a[i][j] = 0;
	r = max({ f(i - 1, j),f(i + 1, j),f(i, j - 1),f(i, j + 1) });
	a[i][j] = 1;
	return ++r;
}
bool solve() {
	int n = input(); if (n == 0)return 0;
	int m = input();
	for1(i, n)for1(j, m)a[i][j] = input();
	int ans = 0; for1(i, n)for1(j, m)ans = max(ans, f(i, j));
	cout << ans << endl;
	for1(i, n)for1(j, m)a[i][j] = 0; return 1;
}
signed main() {
	while (solve());
}
