#include<iostream>
using namespace std;
bool **ice;
int answer;
int compus[4][2]{ {0,1},{1,0},{0,-1},{-1,0} };
void road(int, int, int);
int main() {
	int x, y;
	while (cin >> x >> y&&x){ 
		ice = new bool*[x + 2];
		ice[0] = new bool[y + 2]{ 0 };
		ice[x + 1] = new bool[y + 2]{ 0 };
		for (int i = 1; i <= x; ++i) {
			ice[i] = new bool[y + 2]{0};
			for (int j = 1; j <= y; ++j) {
				cin >> ice[i][j];
			}
		}
		answer = 1;
		for (int i = 1; i <= x; ++i) {
			for (int j = 1; j <= y; ++j) {
				road(i, j, 0);
			}
		}
		cout << answer << endl;
		for (int i = 0; i < y + 2; ++i) {
			delete[] ice[i];
		}
	}
	return 0;
}

void road(int x, int y, int sum) {
	if (ice[x][y]==0) {
		if (answer < sum) {
			answer = sum;
		}
		return;
	}
	++sum;
	for (int i = 0; i < 4; ++i) {
		ice[x][y] = 0;
		road(x + compus[i][0], y + compus[i][1], sum);
		ice[x][y] = 1;
	}
}