loop {
    w, h = gets.split.map &:to_i
    break if w == 0
    max = (1..h).map{ gets.split("").map{|s| s =~ /\d/ ? s.to_i : -1} }
    
    opt = 0 
    (0..h-1).each{|i|
        (0..w-1).each{|j|
            next if max[i][j] < 0 
            m = 0 
            m = max[i-1][j] if i > 0 && max[i-1][j] > m 
            m = max[i][j-1] if j > 0 && max[i][j-1] > m 
            max[i][j] += 10 * m 
            opt = max[i][j] if max[i][j] > opt 
        }
    }   
    p opt 
}