#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i];
    if(i == SZ(s)-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

vector<int> dx = {1, 0};
vector<int> dy = {0, 1};

/* string solve(int h, int w, const vector<vector<char>> &v, vector<vector<string>> &memo, pair<int, int> pos, string now) {
  vector<string> tmp(2);
  REP(i, 2) {
    int y = pos.fi + dy[i], x = pos.se + dx[i];
    if(0 <= y && y < h && 0 <= x && x < w && '0' <= v[y][x] && v[y][x] <= '9') {
      tmp[i] = now + memo[y][x];
    } else {
      tmp[i] = now;
    }
  }

  string res = "";
  if(SZ(tmp[0]) > SZ(tmp[1])) {
    res = tmp[0];
  } else if(SZ(tmp[1]) > SZ(tmp[0])) {
    res = tmp[1];
  } else if(tmp[0] > tmp[1]) {
    res = tmp[0];
  } else {
    res = tmp[1];
  }

  return res;
  if(SZ(memo[pos.fi][pos.se]) < SZ(res) || (SZ(memo[pos.fi][pos.se]) == SZ(res) && memo[pos.fi][pos.se] < res)) {
    memo[pos.fi][pos.se] = res;
  }
  return memo[pos.fi][pos.se];
} */

static bool operator<(string s1, string s2) {
  // cout << s1 << ":" << s2 << endl;
  int cnt1 = 0, cnt2 = 0;
  while(SZ(s1) != 0 && cnt1 != SZ(s1) && s1[cnt1] == '0') {
    cnt1++;
  }
  while(SZ(s2) != 0 && cnt2 != SZ(s2) && s2[cnt2] == '0') {
    cnt2++;
  }

  string tmp1 = (cnt1 == SZ(s1) ? "0" : s1.substr(cnt1, SZ(s1) - cnt1));
  string tmp2 = (cnt2 == SZ(s2) ? "0" : s2.substr(cnt2, SZ(s2) - cnt2));
  if(tmp1 == "0" && tmp2 == "0") {
    return SZ(s1) < SZ(s2);
  } else if(SZ(tmp1) > SZ(tmp2) || (SZ(tmp1) == SZ(tmp2) && tmp1 >= tmp2)) {
    return false;
  } else {
    return true;
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);
  while(1) {
    int w, h; cin >> w >> h;
    if(w == 0 && h == 0) break;
    vector<vector<char>> v(h, vector<char>(w));
    vector<vector<string>> memo(h, vector<string>(w, ""));
    REP(i, h) {
      REP(j, w) {
        cin >> v[i][j];
      }
    }

    string ans = "";
    RREP(i, h-1) {
      RREP(j, w-1) {
        if(!('A' <= v[i][j] && v[i][j] <= 'Z')) {
          string tmp1 = to_string(v[i][j] - '0'), tmp2 = to_string(v[i][j] - '0');
          // cout << tmp1 << ":" << tmp2 << endl;
          if(i != h-1) tmp1 += memo[i+1][j];
          if(j != w-1) tmp2 += memo[i][j+1];
          // cout << tmp1 << ":" << tmp2 << endl;
          string tmp = "";
          if(tmp2 < tmp1) {
            tmp = tmp1;
          } else {
            tmp = tmp2;
          }
          
          // cout << ans << ":" << tmp << endl;
          if(ans < tmp) ans = tmp;
          memo[i][j] = tmp;
          // cout << ans << endl;
        } else {
          memo[i][j] = "";
        }
      }
    }

/*     REP(i, h) {
      REP(j, w) {
        cout << memo[i][j] << " ";
      }
      cout << endl;
    } */

    int cnt = 0;
    if(ans != "0") {
      while(ans[cnt] == '0') cnt++;
    }
    cout << ans.substr(cnt, SZ(ans) - cnt) << endl;
  }
}



Measured memory_bytes: 3424