#include <bits/stdc++.h>
#include "locmin.h"
const int MAXN = 500;
long long mat[MAXN + 2][MAXN + 2];
long long get_val(int l, int c, int N, int M) {
  if(l < 1 || l > N || c < 1 || c > M)
    return 1;
  if(mat[l][c] == 0) {
    mat[l][c] = value(l, c);
    return 0;
  }
  return mat[l][c];
}
int dl[4] = {-1, 0, 1, 0};
int dc[4] = {0, 1, 0, -1};
bool local_max(int l, int c, int N, int M) {
  for( int dir = 0; dir < 4; dir++ ) {
    if(mat[l + dl[dir]][c + dc[dir]] != 0 && mat[l + dl[dir]][c + dc[dir]] < mat[l][c])
      return 0;
  }
  return 1;
}

std::pair<int, int> find_locmin_point(int N, int M) {
  std::priority_queue<std::pair<long long, std::pair<int, int>>> pq;
  int c = rand() % M + 1;
  mat[1][c] = value(1, c);
  pq.push({-mat[1][c], {1, c}});
  while(!pq.empty()){
    int l = pq.top().second.first;
    int c = pq.top().second.second;
    pq.pop();
    for( int dir = 0; dir < 4; dir++ ) {
      if(!get_val(l + dl[dir], c + dc[dir], N, M)) {
        pq.push({-mat[l + dl[dir]][c + dc[dir]], {l + dl[dir], c + dc[dir]}});
      }
    }
    if(local_max(l, c, N, M))
      return {l, c};

  }
}
