## subroutines

def dist_rec(k)
  max_d = 1

  for k0 in $nbrs[k]
    if ! $visited[k0]
      $visited[k0] = true
      max_d = [1 + dist_rec(k0), max_d].max
      $visited[k0] = false
    end
  end

  max_d
end

### main

loop do
  m = gets.strip.to_i
  n = gets.strip.to_i
  mn = m * n
  break if mn == 0

  $brd = []
  n.times do
    $brd += gets.strip.split(' ').map{|s| s.to_i}
  end

  $nbrs = []
  id = 0

  for y in (0...n)
    for x in (0...m)
      $nbrs[id] = []
      if $brd[id] == 1
        $nbrs[id] << (id - 1) if x > 0 && $brd[id - 1] == 1
        $nbrs[id] << (id + 1) if x < m - 1 && $brd[id + 1] == 1
        $nbrs[id] << (id - m) if y > 0 && $brd[id - m] == 1
        $nbrs[id] << (id + m) if y < n - 1 && $brd[id + m] == 1
      end

      id += 1
    end
  end
  #p $nbrs

  $visited = (0...n).map{false}

  max_dist = 0

  for st in (0...n)
    $visited[st] = true
    max_dist = [dist_rec(st), max_dist].max
    $visited[st] = false
  end

  puts max_dist
end