// Arup Guha
// 6/12/2023
// Solution to Kattis Problem: prva
// https://open.kattis.com/problems/prva
// Alternate solution written on 6/9/2026

using namespace std;
#include <bits/stdc++.h>

// Can only move in two ways.
const vector<int> DR = {0,1};
const vector<int> DC = {1,0};

// Global grid
int r, c;
vector<string> grid;

// Function prototypes.
bool isValidStart(int myr, int myc, int dir);
string formWord(int myr, int myc, int dir);
string solve();
string makeBorder(int n);

int main() {

    // Read in the grid.
    cin >> r >> c;

    // Add border row.
    string border = makeBorder(c+2);
    grid.push_back(border);

    // Read the rows and add left, right border.
    for (int i=0; i<r; i++) {
        string tmp;
        cin >> tmp;
        grid.push_back("#"+tmp+"#");
    }

    grid.push_back(border);

    // Solve it!
    cout << solve() << endl;

    return 0;
}

// Returns a string of n copies of '#'.
string makeBorder(int n) {
    string res = "";
    for (int i=0; i<n; i++)
        res += "#";
    return res;
}

// Returns true iff (myr,myc) in direction dir is a valid starting
// spot. Assumes (myr,myc) is inbounds.
bool isValidStart(int myr, int myc, int dir) {

    // Has to start with a letter.
    if (grid[myr][myc] == '#') return false;

    // Needs a hashtag before.
    if (grid[myr-DR[dir]][myc-DC[dir]] != '#') return false;

    // Needs a letter second.
    if (grid[myr+DR[dir]][myc+DC[dir]] == '#') return false;

    // ok if we get here.
    return true;
}

string formWord(int myr, int myc, int dir) {
    string res = "";

    // Keep going as long as we're inbounds.
    while (grid[myr][myc] != '#') {

        // Add in this character.
        res += grid[myr][myc];

        // Advance to next square in direction dir.
        myr += DR[dir];
        myc += DC[dir];
    }

    // This is the string formed in this direction...
    return res;
}

// Returns the solution to the problem.
string solve() {

    string res = "";

    // Try all potential locations/directions.
    for (int i=1; i<=r; i++) {
        for (int j=1; j<=c; j++) {
            for (int k=0; k<DR.size(); k++) {

                // Skip these.
                if (!isValidStart(i,j,k)) continue;

                // A word to consider.
                string tmp = formWord(i,j,k);

                // Two situations to update our answer.
                if (!res.compare("")) res = tmp;
                else if (tmp.compare(res) < 0) res = tmp;
            }
        }
    }

    return res;
}
