#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
use std::cmp::Ordering;
use std::cmp;
use std::collections::BTreeMap;
use std::process;
use std::cmp::Ord;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::collections::BTreeSet;
use std::mem;
use std::collections::BinaryHeap;
/// Equivalent to std::lowerbound and std::upperbound in c++
pub struct Scanner<R> {
    stdin: R,
}
 
impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
fn main(){
    let mut c = 0;
    let sssss = std::io::stdin();
    let mut sc = Scanner { stdin: sssss.lock() };
    fn cp(a:&Vec<i64>, b:&Vec<i64>)->bool{
        for i in (0..a.len()).rev(){
            if a[i]>b[i]{
                return true;
            }
            if a[i]<b[i]{
                return false;
            }
        }
        return true;
    }
    fn dfs(x:usize, y:usize, dp:&mut Vec<Vec<Vec<i64>>>, map:&Vec<Vec<i64>>, dp2:&mut Vec<Vec<i64>>)->Vec<i64>{
        if x>=dp.len() || y>=dp[0].len(){
            return vec![-1;71];
        }
        if map[x][y] == -1{
            return vec![-1;71];
        }
        if dp[x][y][0] != -1{
            return dp[x][y].clone();
        }
        let mut l = (dp2[x][y] - 1) as usize;
        let mut L = vec![-1;71];
        let mut R = vec![-1;71];
        if x+1<dp.len() && l != 0{
            L = dfs(x+1, y, dp, map, dp2);
        }
        if y+1<dp[0].len() && l != 0{
            R = dfs(x, y+1, dp, map, dp2);
        }
        if cp(&L, &R) == false{
            L = R.clone();
        }
        L[l] = map[x][y];
        dp[x][y] = L.clone();
        return L;
    }
    fn dfs2(x:usize, y:usize, dp2:&mut Vec<Vec<i64>>, map:&Vec<Vec<i64>>)->i64{
        if x>=dp2.len() || y>=dp2[0].len(){
            return -1;
        }
        if map[x][y] == -1{
            return -1;
        }
        if dp2[x][y] != -1{
            return dp2[x][y];
        }
        let mut res = 0;
        res = cmp::max(res, dfs2(x+1, y, dp2, map));
        res = cmp::max(res, dfs2(x, y+1, dp2, map));
        dp2[x][y] = res+1;
        return res+1;

    }
    while(true){
        let mut N:usize = sc.read();
        let mut M:usize = sc.read();
        if N==0&&M==0{
            break;
        }
        let mut map = vec![vec![-1;N];M];
        for i in 0..M{
            let mut tt:String = sc.read();
            let cv: Vec<char> = tt.chars().collect();
            for j in 0..N{
                let t = cv[j];
                if '0'<=t && t<='9'{
                    map[i][j] = (t as usize - '0' as usize) as i64;
                }
                else{
                    map[i][j] = -1;
                }
            }
        }
        let mut res = vec![-1;71];
        let mut dp = vec![vec![vec![-1;71];N];M];
        for i in 0..M{
            for j in 0..N{
                if map[i][j] <=0{
                    continue;
                }
                let mut dp2 = vec![vec![-1;N];M];
                dfs2(i, j, &mut dp2, &map);
                let t = dfs(i, j, &mut dp, &map, &mut dp2);
                if cp(&t, &res){
                    res = t.clone();
                }
            }
        }
        let mut flag = false;
        for xxx in (0..71).rev(){
            if res[xxx] == 0 && flag == false{
                continue;
            }
            if res[xxx] != -1 && res[xxx] != 0{
                flag = true;
                print!("{}", res[xxx]);
            }
            if res[xxx] == 0 && flag == true{
                print!("{}",res[xxx]);
            }
        }
        println!();
    }
}

pub static MOD:i64 = 1000000007;
pub static MODu:usize = 1000000007;
pub static eps:f64 = 1e-8;
const INF: i64 = 1 << 60;






Measured memory_bytes: 5072