while 1:

    W,H = list(map(int,input().split()))

    if W == 0: break

    C = [list(input()) for _ in range(H)]

    

    dp = [["0"]*W for _ in range(H)]

    ans = 0

    for h in range(H):

        for w in range(W):

            if C[h][w].isdigit():

                dp[h][w] = str(max(int(dp[h][w]),int(C[h][w])))

                if w > 0: dp[h][w] = str(max(int(dp[h][w]),int(dp[h][w-1]+C[h][w])))

                if h > 0: dp[h][w] = str(max(int(dp[h][w]),int(dp[h-1][w]+C[h][w])))

                ans = max(ans, int(dp[h][w]))

    print(ans)
while 1:

    W,H = list(map(int,input().split()))

    if W == 0: break

    C = [list(input()) for _ in range(H)]

    dp = [[0]*W for _ in range(H)]

    ans = 0

    for h in range(H):

        for w in range(W):

            if C[h][w].isdigit():

                dp[h][w] = max(dp[h][w],int(C[h][w]))

                if w > 0: dp[h][w] = max(dp[h][w],int(str(dp[h][w-1])+C[h][w]))

                if h > 0: dp[h][w] = max(dp[h][w],int(str(dp[h-1][w])+C[h][w]))

                ans = max(ans,dp[h][w])

    print(ans)
while 1:
    W, H = list(map(int, input().split()))
    if W == 0:
        break
    C = [list(input()) for _ in range(H)]
    dp = [["0"] * W for _ in range(H)]
    ans = 0
    for h in range(H):
        for w in range(W):
            if C[h][w].isdigit():
                dp[h][w] = str(max(int(dp[h][w]), int(C[h][w])))
                if w > 0:
                    dp[h][w] = str(max(int(dp[h][w]), int(dp[h][w - 1] + C[h][w])))
                if h > 0:
                    dp[h][w] = str(max(int(dp[h][w]), int(dp[h - 1][w] + C[h][w])))
                ans = max(ans, int(dp[h][w]))
    print(ans)

while 1:
    W, H = list(map(int, input().split()))
    if W == 0:
        break
    C = [list(input()) for _ in range(H)]
    dp = [[0] * W for _ in range(H)]
    ans = 0
    for h in range(H):
        for w in range(W):
            if C[h][w].isdigit():
                dp[h][w] = max(dp[h][w], int(C[h][w]))
                if w > 0:
                    dp[h][w] = max(dp[h][w], int(str(dp[h][w - 1]) + C[h][w]))
                if h > 0:
                    dp[h][w] = max(dp[h][w], int(str(dp[h - 1][w]) + C[h][w]))
                ans = max(ans, dp[h][w])
    print(ans)

-    dp = [["0"] * W for _ in range(H)] +    dp = [[0] * W for _ in range(H)] -                dp[h][w] = str(max(int(dp[h][w]), int(C[h][w]))) +                dp[h][w] = max(dp[h][w], int(C[h][w])) -                    dp[h][w] = str(max(int(dp[h][w]), int(dp[h][w - 1] + C[h][w]))) +                    dp[h][w] = max(dp[h][w], int(str(dp[h][w - 1]) + C[h][w])) -                    dp[h][w] = str(max(int(dp[h][w]), int(dp[h - 1][w] + C[h][w]))) -                ans = max(ans, int(dp[h][w])) +                    dp[h][w] = max(dp[h][w], int(str(dp[h - 1][w]) + C[h][w])) +                ans = max(ans, dp[h][w])