loop do
    w, h = gets.split.map(&:to_i)
    break if w == 0 && h == 0
    c = h.times.map{gets.strip}
    dp = Array.new(h).map{Array.new(w,0)}
    max = 0
    c.each_with_index do |r,i|
        r.each_char.with_index do |ch, j|
            next if ch.to_s.match(/[A-Z]/)
            if i == 0
                if j == 0
                    dp[i][j] = ch.to_i
                else
                    dp[i][j] = (dp[i][j-1].to_s + ch).to_i
                end
            else
                if j == 0
                    dp[i][j] = (dp[i-1][j].to_s + ch).to_i
                else
                    dp[i][j] = ([dp[i-1][j], dp[i][j-1]].max.to_s + ch).to_i
                end
            end
        end
        max = [max, dp[i].max].max
    end
    puts max
end