#include <iostream>
using namespace std;

int n, m;
int field[90][90];
bool visited[90][90];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int solve(int x, int y) {
  visited[y][x] = true;
  int ret = 0;
  for (int i = 0; i < 4; i++) {
    int nx = dx[i] + x;
    int ny = dy[i] + y;
    if (!visited[ny][nx] && 0 <= nx && nx < n && 0 <= ny && ny < m && field[ny][nx] == 1) {
      ret = max(ret, solve(nx, ny) + 1);
    }
  }
  visited[y][x] = false;
  return ret;
}

int main(void) {
  while (cin >> n >> m, n && m) {
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        cin >> field[i][j];
        visited[i][j] = false;
      }
    }
    int ans = -1;
    for (int x = 0; x < n; x++) {
      for (int y = 0; y < m; y++) {
        ans = max(solve(x, y), ans);
      }
    }
    cout << ans << endl;
  }
  return 0;
}