#include <bits/stdc++.h>
#include "locmin.h"
const int MAXN = 500;
long long mat[MAXN + 2][MAXN + 2];
int n, m;
long long get_val(int l, int c) {
  if(l < 1 || l > n || c < 1 || c > m)
    return 1e18 + 1;
  if(mat[l][c] == 0) {
    mat[l][c] = value(l, c);
  }
  return mat[l][c];
}
int dl[4] = {-1, 0, 1, 0};
int dc[4] = {0, 1, 0, -1};
bool inmat(int l, int c) {
  return (1 <= l && l <= n && 1 <= c && c <= m);
}
bool local_min(int l, int c) {
  for( int dir = 0; dir < 4; dir++ ) {
    int newl = l + dl[dir];
    int newc = c + dc[dir];
    if(inmat(newl, newc) && get_val(newl, newc) < get_val(l, c))
      return 0;
  }
  return 1;
}
std::pair<int, int> find_all_points(int x, int type) {
  int upper = (type == 0 ? m + 1 : n + 1);
  int st = 0;
  int dr = upper; // pe linie / pe coloana
  while(dr - st > 1) {
    int mij = (st + dr) / 2;
    long long a, b;
    if(type == 0) {
      a = get_val(x, mij - 1);
      b = get_val(x, mij);
    }else {
      a = get_val(mij - 1, x);
      b = get_val(mij, x);
    }
    if(a < b)
      dr = mij;
    else
      st = mij;
  }
  if(type == 0)
    return {x, dr - 1};
  else
    return {dr - 1, x};
}
bool discarded[MAXN + 2][2];
int viz[MAXN + 2][MAXN + 2];
std::pair<int, int> find_locmin_point(int N, int M) {
  n = N;
  m = M;
  int typern = 1;
  for( int l = 1; l <= n; l++ ) {
    std::pair<int, int> v = find_all_points(l, 0);
    if(local_min(v.first, v.second))
      return v;
  }
}
/*
2 5
6 5 4 3 2
1 2 3 4 1
*/
