import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class ArrayRunnerSolver
{
    public static void main( String[] args )
    {
        
        loadArray();
        b = new BestPath();
        LocalFileChecker lf = new LocalFileChecker( dataArray, b );
        lf.start();
    }

    static private void loadArray()
    {
        try
        {
            BufferedReader input = new BufferedReader( 
                                   new InputStreamReader( System.in ) );
            String read = input.readLine();
            width = (new Integer( read.substring( 0, 
                                  read.indexOf( ' ')).trim())).intValue();
            height = (new Integer( read.substring( read.indexOf( ' ' )+1,
                                   read.length() ).trim() ) ).intValue();
            dataArray = new char[width][height]; 
            for( int i=0;i<height;i++)
            {
                read = input.readLine();
                for( int j=0;j<width;j++)
                {
                    dataArray[j][i] = read.charAt( j ); 
                }
            }
        }
        catch( java.io.IOException e )
        {
            System.out.println( "Error from reading console" );
        }
    }

    static char[][] dataArray;
    static FileInputStream file;
    static int height;
    static int width;
    static BestPath b;
}

