$x=0
$y=0
$bord = []

loop{
	line = gets
	if line==nil then
		break
	end
	sp = line.split(nil)
	
	if sp.count() != 2 then
		break
	else
		$x = sp[0].to_i()
		$y = sp[1].to_i()
		if $x == 0 and $y == 0 then
			break
		end
		$bord = Array.new($y).map{Array.new($x,0)}
		max = 0
		for i in 0..$y-1
			line = gets
			left = 0
			for j in 0..$x-1
				tmp = 0
				if line[j] =~ /\d/ then
					tmp = line[j].to_i() 
					if i > 0 then
						up = $bord[i-1][j]
					else
						up = 0
					end

					if up > left then
						tmp += up * 10					
					else
						tmp += left * 10
					end
					
					if tmp > max then
						max = tmp
					end
				end
				$bord[i][j] = tmp
				left = tmp
			end
		end
		print max
		print("\n")
	end
}