using System;

namespace FinalSvetskogPrvenstva
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 5;
            int m = 5;

            int[,] matrica = new int[n, m]
            {
                { 1, 3, 2, 5, 4 },
                { 2, 2, 1, 2, 3 },
                { 5, 4, 5, 4, 1 },
                { 2, 3, 4, 3, 2 },
                { 3, 5, 1, 3, 1 }
            };

            int[] niz = new int[2];
            niz[0] = matrica[0, 0];

            int xHotel = 0;
            int yHotel = 0;
            int xStadion = n - 1;
            int yStadion = m - 1;

            int x = xHotel;
            int y = yHotel;

            while (x != xStadion || y != yStadion)
            {
                if (y < yStadion)
                {
                    y++;
                }
                else if (x < xStadion)
                {