Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int w,h;
vector<string> data;

int dx[2]={1,0};
int dy[2]={0,1};
bool inrange(int x,int y){ 
	if(x<0||y<0||x>h-1||y>w-1) return false;
	else return true;
}

long long int conv(string str){
	if(str=="") return -1;
	REP(i,str.size()) {
		if(str[i]<'0'||str[i]>'9') {
			return -1;
		}
	}
	cout << str << endl;
	return stoll(str);
}

string getbigger(string a,string b){
	if(a.size()!=b.size()){
		if(a.size()>b.size()) return a;
		else return b;
	}
	else{
		REP(i,a.size()){
			if(a[i]==b[i]) continue;
			if(a[i]>b[i]) return a;
			else  return b;
		}
		return a;//eq
	}
}

string solve(int px,int py,bool sudeni[100][100]){

	string rst = "";
	if(!inrange(px,py)) return "";
	if(sudeni[px][py]==false && '0'<=data[px][py] && data[px][py]<='9') {
		rst+=data[px][py];
		sudeni[px][py] = true;
	}
	vector<string> tmp;
	REP(i,2){
		tmp.pb("");
		int nx = px + dx[i];
		int ny = py + dy[i];
		if(inrange(nx,ny) && sudeni[nx][ny]==false && '0'<=data[nx][ny] && data[nx][ny]<='9') {
			tmp[i]=solve(nx,ny,sudeni);
		}
	}
	rst += getbigger(tmp[0],tmp[1]);
	return  rst;
}

int main(){
	while(1){
		cin >> w >> h;
		if(w==0&&h==0) break;
		data.clear();
		REP(i,h){
			string tmp;
			cin >> tmp;
			data.pb(tmp);
		}
		string ans = "-1";
		REP(i,h){
			REP(j,w){
				bool s[100][100];
				REP(i,100) REP(j,100) s[i][j]=false;
				ans = getbigger(solve(i,j,s),ans);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'std::string solve(int, int, bool (*)[100])':
a.cc:66:42: error: reference to 'data' is ambiguous
   66 |         if(sudeni[px][py]==false && '0'<=data[px][py] && data[px][py]<='9') {
      |                                          ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:27:16: note:                 'std::vector<std::__cxx11::basic_string<char> > data'
   27 | vector<string> data;
      |                ^~~~
a.cc:66:58: error: reference to 'data' is ambiguous
   66 |         if(sudeni[px][py]==false && '0'<=data[px][py] && data[px][py]<='9') {
      |                                                          ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:27:16: note:                 'std::vector<std::__cxx11::basic_string<char> > data'
   27 | vector<string> data;
      |                ^~~~
a.cc:67:22: error: reference to 'data' is ambiguous
   67 |                 rst+=data[px][py];
      |                      ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:27:16: note:                 'std::vector<std::__cxx11::basic_string<char> > data'
   27 | vector<string> data;
      |                ^~~~
a.cc:75:68: error: reference to 'data' is ambiguous
   75 |                 if(inrange(nx,ny) && sudeni[nx][ny]==false && '0'<=data[nx][ny] && data[nx][ny]<='9') {
      |                                                                    ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:27:16: note:                 'std::vector<std::__cxx11::basic_string<char> > data'
   27 | vector<string> data;
      |                ^~~~
a.cc:75:84: error: reference to 'data' is ambiguous
   75 |                 if(inrange(nx,ny) && sudeni[nx][ny]==false && '0'<=data[nx][ny] && data[nx][ny]<='9') {
      |                                                                                    ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:27:16: note:                 'std::vector<std::__cxx11::basic_string<char> > data'
   27 | vector<string> data;
      |                ^~~~
a.cc: In function 'int main()':
a.cc:87:17: error: reference to 'data' is ambiguous
   87 |                 data.clear();
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:27:16: note:                 'std::vector<std::__cxx11::basic_string<char> > data'
   27 | vector<string> data;
      |                ^~~~
a.cc:91:25: error: reference to 'data' is ambiguous
   91 |                         data.pb(tmp);
      |                         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:27:16: note:                 'std::vector<std::__cxx11::basic_string<char> > data'
   27 | vector<string> data;
      |                ^~~~