#include <utility>
#include <vector>
long long value(int, int);
std::pair<int, int> find_locmin_point(int N, int M) {
  std::vector<std::vector<long long>> grid(N, std::vector<long long>(M, -1));
  std::vector<std::vector<bool>> vis(N, std::vector<bool>(M, false));
  int x = 0, y = 0;
  grid[0][0] = value(1, 1);
  while(true) {
    vis[x][y] = true;
    int nx, ny;
    bool fail = false;
    if(x != N-1) {
      long long r = grid[x+1][y] == -1 ? (grid[x+1][y] = value(x+2, y+1)) : grid[x+1][y];
      if(r < grid[x][y]) {
        if(vis[x+1][y]) {
          fail = true;
          nx = x+1;
          ny = y;
        } else {
          ++x;
          continue;
        }
      }
    }
    if(y != M-1) {
      long long r = grid[x][y+1] == -1 ? (grid[x][y+1] = value(x+1, y+2)) : grid[x][y+1];
      if(r < grid[x][y]) {
        if(vis[x][y+1]) {
          fail = true;
          nx = x;
          ny = y+1;
        } else {
          ++y;
          continue;
        }
      }
    }
    if(x != 0) {
      long long r = grid[x-1][y] == -1 ? (grid[x-1][y] = value(x, y+1)) : grid[x-1][y];
      if(r < grid[x][y]) {
        if(vis[x-1][y]) {
          fail = true;
          nx = x-1;
          ny = y;
        } else {
          --x;
          continue;
        }
      }
    }
    if(y != 0) {
      long long r = grid[x][y-1] == -1 ? (grid[x][y-1] = value(x+1, y)) : grid[x][y-1];
      if(r < grid[x][y]) {
        if(vis[x][y-1]) {
          fail = true;
          nx = x;
          ny = y-1;
        } else {
          --x;
          continue;
        }
      }
    }
    if(fail) {
      x = nx;
      y = ny;
      continue;
    }
    return {x+1, y+1};
  }
}
