#include <iostream>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int m, n;
bool tront[90][90];
bool memo[90][90];

int dfs(int y, int x) {
	int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
	int rep = 0;

	REP(i, 4) {
		int nx = x + dx[i], ny = y + dy[i];
		if (! (nx >= 0 && nx < m && ny >= 0 && ny < n)) continue;
		if (! tront[ny][nx] || memo[ny][nx]) continue;
		memo[ny][nx] = true;
		rep = max(rep, dfs(ny, nx));
		memo[ny][nx] = false;
	}
	return rep + 1;
}


int main() {
	while (true) {
		int ans = 0;
		cin >> m >> n;
		if (n == 0 && m == 0) break;
		REP(i, n) REP(j, m) cin >> tront[i][j];

		REP(i, n) REP(j, m) if (tront[i][j]) {
			memo[i][j] = true;
			ans = max(ans, dfs(i, j));
			memo[i][j] = false;
		}

		cout << ans << endl;
	}
	return 0;
}