/*#include<iostream>
using namespace std;
static const int MAXN=500,MAXM=500;
static long long int tab[MAXN][MAXM];
static int n,m;
static void finish (string message) {
    cout << message << endl ;
    exit(0);
}

static int cnt=0;
long long int value (int row, int col) {
    row--; col--;
    if ((row<0)||(row>=n)||(col<0)||(col>=m)) finish("Invalid row or column number in question ("+to_string(row)+","+to_string(col)+")!");
    cnt++;
    if (cnt>n*m) finish("Too many questions!");
    return tab[row][col];
}
extern pair <int, int> find_locmin_point (int, int);

static int drow[]={ -1, -0, +0, +1 };
static int dcol[]={ -0, -1, +1, +0 };
static bool check_saddle (int row, int col) {
    for (int i=0; i<4; i++) {
        int r=row+drow[i],c=col+dcol[i];
        if ((r<0)||(r>=n)||(c<0)||(c>=m)) continue;
        if (tab[r][c]<=tab[row][col]) return false;
    }
    return true;
}*/
#include "locmin.h"
#include <utility>
using namespace std;
int long long Ma[510][510];
std::pair <int, int> find_locmin_point(int N, int M)
{
    int long long a,b,c,sol,st,dr,mij;

    if (N==1)
    {
        st=1;
        dr=M;
        while (st<=dr)
        {
            int mij=(st+dr)/2;
            if (Ma[1][mij]==0) a=value(1,mij),Ma[1][mij]=a;
            else a=Ma[1][mij];


            if (Ma[1][mij-1]==0)
            {
                if (mij>1) b=value(1,mij-1),Ma[1][mij-1]=b;
                else b=2000000000000000000;
            }
            else b=Ma[1][mij-1];

            if (Ma[1][mij+1]==0)
            {
                if (mij<M) c=value(1,mij+1),Ma[1][mij+1]=c;
                else c=2000000000000000000;
            }
            else c=Ma[1][mij+1];

         //   cout<<mij<<" ";
            if (a<b && a<c) {sol=mij; break;}
            else if (a>b) dr=mij-1;
            else st=mij+1;
        }
    }

    return {1,sol};
}
/*
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m ;
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            cin >> tab[i][j] ;
        }
    }
    int r,c;
    pair<int,int>rr;
     rr=find_locmin_point(n,m);
     r=rr.first;
     c=rr.second;
    cout << "Answer cell: (" << r << "," << c << ")\n";
    cout << "Number of value calls: " << cnt << endl ;
    r--; c--;
    if ((r<0)||(r>=n)||(c<0)||(c>=m)) finish("Invalid row or column in answer!");
    if (check_saddle(r,c)==false) finish("Answer is not a local minimum point!");
    finish("Correctly found local minimum point.");
    return 0;
}*/
