You are given n arrays a_1, a_2, ..., a_n; each array consists of exactly m integers. We denote the y-th element of the x-th array as a_{x, y}.

You have to choose two arrays a_i and a_j (1 ≤ i, j ≤ n, it is possible that i = j). After that, you will obtain a new array b consisting of m integers, such that for every k ∈ [1, m] b_k = max(a_{i, k}, a_{j, k}).

Your goal is to choose i and j so that the value of min _{k = 1}^{m} b_k is maximum possible.

Input

The first line contains two integers n and m (1 ≤ n ≤ 3 ⋅ 10^5, 1 ≤ m ≤ 8) — the number of arrays and the number of elements in each array, respectively.

Then n lines follow, the x-th line contains the array a_x represented by m integers a_{x, 1}, a_{x, 2}, ..., a_{x, m} (0 ≤ a_{x, y} ≤ 10^9).

Output

Print two integers i and j (1 ≤ i, j ≤ n, it is possible that i = j) — the indices of the two arrays you have to choose so that the value of min _{k = 1}^{m} b_k is maximum possible. If there are multiple answers, print any of them.

Example

Input


6 5
5 0 3 1 2
1 8 9 1 3
1 2 3 4 5
9 1 0 3 7
2 3 0 6 3
6 4 1 7 0


Output


1 5

Source: codeforces | Difficulty: HARD
Tags: Dynamic programming

Bit manipulation

Sorting


Solutions:
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 30, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
(n, m) = map(int, input().split())
l = []
pm = 2 ** m - 1
for i in range(n):
	l.append(list(map(int, input().split())))

def find(x):
	s = set()
	d = defaultdict(int)
	for i in range(n):
		a = ''
		for j in range(m):
			if l[i][j] >= x:
				a += '1'
			else:
				a += '0'
		d[int(a, 2)] = i
		s.add(int(a, 2))
	s = list(s)
	for i in range(len(s)):
		for j in range(i, len(s)):
			if s[i] | s[j] == pm:
				return [d[s[i]] + 1, d[s[j]] + 1]
	return [-1, -1]
st = 0
end = 10 ** 9
ans = (0, 0)
while st <= end:
	mid = (st + end) // 2
	s = find(mid)
	if s[0] != -1:
		ans = s
		st = mid + 1
	else:
		end = mid - 1
print(*ans)


import sys
from collections import defaultdict
input = sys.stdin.readline
(n, m) = map(int, input().split())
vals = set()
locs = defaultdict(list)
for i in range(n):
	inp = map(int, input().split())
	for (pos, v) in enumerate(inp):
		vals.add(v)
		locs[v].append((pos, i))
masks = [0] * n
full = (1 << m) - 1
met = {0: 0}
for v in sorted(vals, reverse=True):
	for (pos, i) in locs[v]:
		curr_mask = masks[i] = masks[i] | 1 << pos
		met[curr_mask] = i
		complement = full ^ curr_mask
		if complement in met:
			print(i + 1, met[complement] + 1)
			sys.exit()


import sys
from collections import defaultdict
reader = (map(int, line.split()) for line in sys.stdin)
input = reader.__next__
(n, m) = input()
elems = set()
vals = defaultdict(list)
for i in range(n):
	for (pos, v) in enumerate(input()):
		elems.add(v)
		vals[v].append((pos, i))
elems = sorted(elems, reverse=True)
masks = [0] * n
full = (1 << m) - 1
met = {0: 0}
for v in elems:
	for (pos, i) in vals[v]:
		curr_mask = masks[i] = masks[i] | 1 << pos
		met[curr_mask] = i
		complement = full ^ curr_mask
		if complement in met:
			print(i + 1, met[complement] + 1)
			sys.exit()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))
mod = 1000000007

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

def YES():
	print('YES')

def NO():
	print('NO')

def Yes():
	print('Yes')

def No():
	print('No')
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def lcm(a, b):
	return abs(a // gcd(a, b) * b)

def comb(n, r):
	if n < r:
		return 0
	else:
		return fac[n] * (finv[r] * finv[n - r] % mod) % mod

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def arr1d(n, v):
	return [v] * n

def arr2d(n, m, v):
	return [[v] * m for _ in range(n)]

def arr3d(n, m, p, v):
	return [[[v] * p for _ in range(m)] for i in range(n)]

def solve():
	(n, m) = sep()
	ar = []
	for i in range(n):
		ar.append(lis())

	def isvalid(k):
		val = [0] * 2 ** m
		for i in range(n):
			temp = 0
			for j in range(m):
				if ar[i][j] >= k:
					temp += 1 << j
			val[temp] = 1
		valu = []
		for i in range(2 ** m):
			if val[i] == 1:
				valu.append(i)
		req = 2 ** m - 1
		for i in valu:
			for j in valu:
				if i | j == req:
					return 1
		return 0

	def search():
		l = 0
		r = 10 ** 9 + 1
		for i in range(30):
			if l == r:
				return l
			m = (l + r) // 2
			tempc = isvalid(m)
			if tempc and (not isvalid(m + 1)):
				return m
			if tempc:
				l = m
			else:
				r = m
		return m
	k = search()
	val = defaultdict(int)
	for i in range(n):
		temp = 0
		for j in range(m):
			if ar[i][j] >= k:
				temp += 1 << j
		val[temp] = i
	req = 2 ** m - 1
	for i in val.keys():
		for j in val.keys():
			if i | j == req:
				print(val[i] + 1, val[j] + 1)
				return
solve()


import sys
input = sys.stdin.readline
from itertools import combinations
from collections import defaultdict
(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
mx = max((max(a[i]) for i in range(n)))
if n == 1:
	print(1, 1)
	exit()
l = 0
r = mx + 1
while l + 1 < r:
	flg = 0
	x = (l + r) // 2
	jud = set()
	dc = defaultdict(int)
	for i in range(n):
		jnum = 0
		for j in range(m):
			if a[i][j] >= x:
				jnum += 1 << j
		if dc[jnum] == 0:
			dc[jnum] = i + 1
		if jnum == (1 << m) - 1:
			flg = 1
			if i == 0:
				ans = (i + 1, i + 2)
			else:
				ans = (1, i + 1)
		jud.add(jnum)
	for (p, q) in combinations(jud, 2):
		if p | q == (1 << m) - 1:
			flg = 1
			ans = (dc[p], dc[q])
	if flg:
		l = x
	else:
		r = x
if l == 0:
	print(1, 2)
else:
	print(*ans)


import sys
inp = sys.stdin.readline
input = lambda : inp().strip()
flush = sys.stdout.flush

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def main():
	(n, m) = lin()
	a = [lin() for i in range(n)]
	sl = 2 ** m - 1
	(l, r) = (0, 10 ** 9)
	sol = [1, 1]
	sol1 = 0
	while l < r:
		md = l + r + 1 >> 1
		ans1 = 0
		done = 1
		a2 = [0] * (sl + 1)
		for i in range(n):
			ch = 0
			for j in range(m):
				ch = (ch << 1) + (a[i][j] >= md)
			a2[ch] = i + 1
		for i in range(sl + 1):
			if done:
				if a2[i]:
					for j in range(i + 1):
						if a2[j] and i | j == sl:
							done = 0
							ans1 = [a2[i], a2[j]]
			else:
				break
		if ans1:
			if sol1 < md:
				sol1 = md
				sol = ans1
			l = md
		else:
			r = md - 1
	print(sol[0], sol[1])
main()


import sys
input = sys.stdin.buffer.readline

def find_pair(candidate, data, m):
	ans = (-1, -1)
	binary_bit = [False for i in range(1 << m)]
	for i in data:
		bit_tmp = 0
		for j in range(len(i)):
			if i[j] >= candidate:
				bit_tmp |= 1 << j
		binary_bit[bit_tmp] = True
	for i in range(1 << m):
		for j in range(1 << m):
			if i | j == (1 << m) - 1 and binary_bit[i] and binary_bit[j]:
				ans = (i, j)
				break
	return ans

def backtracking(candidate, ans, data):
	idx_i = -1
	idx_j = -1
	for i in range(len(data)):
		bit_tmp = 0
		for j in range(len(data[i])):
			if data[i][j] >= candidate:
				bit_tmp |= 1 << j
		if bit_tmp == ans[0]:
			idx_i = i
		if bit_tmp == ans[1]:
			idx_j = i
	print(str(idx_i + 1) + ' ' + str(idx_j + 1))

def main():
	(n, m) = [int(i) for i in input().split()]
	data = [[int(i) for i in input().split()] for i in range(n)]
	a = 0
	b = 10 ** 9 + 7
	ans = (-1, -1)
	candidate = -1
	while a <= b:
		mid = (a + b) // 2
		bin_ans = find_pair(mid, data, m)
		if bin_ans[0] != -1 and bin_ans[1] != -1:
			ans = bin_ans
			candidate = mid
			a = mid + 1
		else:
			b = mid - 1
	backtracking(candidate, ans, data)
main()


import io
import os
from collections import Counter, defaultdict, deque
DEBUG = False

def bisect_f(f, lo, hi):
	if DEBUG:
		assert f(lo) and (not f(hi))
	while hi - lo > 1:
		mid = (lo + hi) // 2
		if f(mid):
			lo = mid
		else:
			hi = mid
		if DEBUG:
			assert f(lo) and (not f(hi))
	if DEBUG:
		assert hi - lo == 1
		assert f(lo) and (not f(hi))
	return lo

def solve(N, M, arrs):

	def isPossible(target):
		possible = set()
		for arr in arrs:
			mask = 0
			for (pos, x) in enumerate(arr):
				if x >= target:
					mask += 1 << pos
			possible.add(mask)
		allMask = (1 << M) - 1
		for mask1 in possible:
			for mask2 in possible:
				if mask1 | mask2 == allMask:
					return (mask1 << 8) + mask2
		return 0
	lo = min(arrs[0])
	hi = 10 ** 9 + 1
	index = bisect_f(isPossible, lo, hi)
	(mask1, mask2) = divmod(isPossible(index), 1 << 8)
	ans = [-1, -1]
	for (i, arr) in enumerate(arrs):
		mask = 0
		for (pos, x) in enumerate(arr):
			if x >= index:
				mask += 1 << pos
		if mask == mask1:
			ans[0] = str(i + 1)
		if mask == mask2:
			ans[1] = str(i + 1)
	return ' '.join(ans)
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N, M) = [int(x) for x in input().split()]
arrs = [[int(x) for x in input().split()] for i in range(N)]
ans = solve(N, M, arrs)
print(ans)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
(n, m) = map(int, input().split())
a = []
for i in range(n):
	ai = list(map(int, input().split()))
	a.append(ai)

def check(mid):
	mask = (1 << m) - 1
	s = set()
	d = dict()
	for i in range(n):
		state = 0
		for j in range(m):
			if a[i][j] >= mid:
				state += 1 << j
		if state in s:
			continue
		s.add(state)
		k = state
		while k >= 0:
			k &= state
			d[k] = i
			k -= 1
		need = mask ^ state
		if need in d:
			(q1, q2) = (d[need], i)
			if q1 > q2:
				(q1, q2) = (q2, q1)
			return (True, (q1, q2))
	return (False, (-1, -1))
left = 0
right = 10 ** 9 + 1
(i, j) = (0, 0)
while right - left > 1:
	mid = (right + left) // 2
	(flag, (q1, q2)) = check(mid)
	if flag:
		left = mid
		(i, j) = (q1, q2)
	else:
		right = mid
print(i + 1, j + 1)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bisearch_max(mn, mx, func):
	ok = mn
	ng = mx
	while ok + 1 < ng:
		mid = (ok + ng) // 2
		if func(mid):
			ok = mid
		else:
			ng = mid
	return ok

def check(m):
	ok = [0] * N
	S = set()
	for i in range(N):
		for j in range(M):
			if A[i][j] >= m:
				ok[i] |= 1 << j
		S.add(ok[i])
	full = (1 << M) - 1
	for bit1 in range(1 << M):
		for bit2 in range(bit1, 1 << M):
			if bit1 in S and bit2 in S:
				if bit1 | bit2 == full:
					return True
	return False
(N, M) = MAP()
A = [None] * N
for i in range(N):
	A[i] = LIST()
res = bisearch_max(0, 10 ** 9 + 1, check)
ok = [0] * N
S = set()
D = {}
for i in range(N):
	for j in range(M):
		if A[i][j] >= res:
			ok[i] |= 1 << j
	S.add(ok[i])
	D[ok[i]] = i + 1
full = (1 << M) - 1
for bit1 in range(1 << M):
	for bit2 in range(bit1, 1 << M):
		if bit1 in S and bit2 in S:
			if bit1 | bit2 == full:
				print(D[bit1], D[bit2])
				exit()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def check(mid: int) -> bool:
	global ans
	dic = {}
	for i in range(n):
		bit = 0
		for j in range(m):
			if a[i][j] >= mid:
				bit += 1
			bit <<= 1
		dic[bit >> 1] = i
	for (x, idx) in dic.items():
		for (y, idy) in dic.items():
			if x | y == 2 ** m - 1:
				ans = (idx + 1, idy + 1)
				return True
	return False
(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
ans = []
le = 0
ri = int(1000000000.0)
while le <= ri:
	mid = le + ri >> 1
	if check(mid):
		le = mid + 1
	else:
		ri = mid - 1
print(ans[0], ans[1])


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, m) = map(lambda x: int(x), input().split())
A = []
for _ in range(n):
	scores = list(map(lambda x: int(x), input().split()))
	A.append(scores)

def solve(n, m, A):
	ans = ()
	nstats = 2 ** m

	def judge(finalScore):
		nonlocal ans
		seen = {}
		for (i, scores) in enumerate(A):
			sta = 0
			for e in scores:
				sta = sta * 2 + (e >= finalScore)
			seen[sta] = i
		for i in range(nstats):
			for j in range(nstats):
				if i | j == nstats - 1 and i in seen and (j in seen):
					ans = (seen[i], seen[j])
					return True
		return False
	l = 0
	r = 2 ** 31 - 1
	while l < r:
		m = l + (r - l) // 2
		if not judge(m):
			r = m
		else:
			l = m + 1
	print(ans[0] + 1, ans[1] + 1)
solve(n, m, A)


import collections
import time
import os
import sys
import bisect
import heapq
from typing import List

def check(val, A, M):
	s = set()
	for row in A:
		v = 0
		for u in row:
			v <<= 1
			if u >= val:
				v |= 1
		s.add(v)
	x = 1 << M
	for u in s:
		for v in range(x):
			if v in s and u | v == x - 1:
				return True
	return False

def getAnswer(val, A, M):
	vi = {}
	for (i, row) in enumerate(A):
		v = 0
		for u in row:
			v <<= 1
			if u >= val:
				v |= 1
		vi[v] = i
	x = 1 << M
	for u in vi:
		for v in range(x):
			if v in vi and u | v == x - 1:
				return (vi[u], vi[v])
	return (0, 0)

def solve(N, M, A):
	(lo, hi) = (0, max([max(row) for row in A]))
	while lo <= hi:
		m = (lo + hi) // 2
		if check(m, A, M):
			lo = m + 1
		else:
			hi = m - 1
	(a, b) = getAnswer(hi, A, M)
	print('{} {}'.format(a + 1, b + 1))
(N, M) = map(int, input().split())
A = []
for i in range(N):
	row = [int(x) for x in input().split()]
	A.append(row)
solve(N, M, A)


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from collections import defaultdict
(n, m) = [int(i) for i in input().split()]
a = []
mi = -1
ma = 10 ** 9
for i in range(n):
	a.append([int(j) for j in input().split()])
ans = []
while mi < ma:
	mid = (mi + ma + 1) // 2
	masks = {}
	for i in range(n):
		currMask = 0
		for j in range(m):
			if a[i][j] >= mid:
				currMask += 1 << j
		masks[currMask] = i
	req = (1 << m) - 1
	possible = 0
	for i in masks:
		for j in masks:
			if i | j == req:
				possible = 1
				ans = [masks[i] + 1, masks[j] + 1]
				break
		if possible:
			break
	if possible:
		mi = mid
	else:
		ma = mid - 1
print(*ans)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
l = -1
r = 10 ** 9 + 1
(ans1, ans2) = (-1, -1)
while r - l > 1:
	x = (l + r) // 2
	idx = {}
	for i in range(n):
		v = 0
		for j in range(m):
			if a[i][j] >= x:
				v += 1
			v <<= 1
		idx[v >> 1] = i
	ok = False
	(idx1, idx2) = (0, 0)
	for (aa, bb) in idx.items():
		for (cc, dd) in idx.items():
			for d in range(m):
				if aa | cc == 2 ** m - 1:
					ok = True
					idx1 = bb + 1
					idx2 = dd + 1
	if ok:
		l = x
		ans1 = idx1
		ans2 = idx2
	else:
		r = x
print(ans1, ans2)


INF = 10 ** 10

def main():
	(n, m) = get_list()
	mat = [get_list() for _ in range(n)]

	def fn(x):
		st = [-1] * (1 << m)
		st[0] = 0
		for (index, li) in enumerate(mat):
			no = 0
			for (i, ele) in enumerate(li):
				if ele >= x:
					no |= 1 << i
			li = [0]
			k = 2 ** m - 1 - no
			if st[k] > -1:
				return (True, st[k], index)
			b = 0
			b = b - no & no
			while b != 0:
				st[b] = index
				b = b - no & no
			continue
		return (False, -1, -1)
	x = 0
	base = 10 ** 8
	while base > 0:
		while fn(x + base)[0]:
			x += base
		base //= 2
	(res, a, b) = fn(x)
	print(a + 1, b + 1)
import sys
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
main()


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]

def get_ans(x):
	lim = 1 << m
	match = lim - 1
	track = [-1 for i in range(lim)]
	for i in range(n):
		mask = 0
		for j in range(m):
			if a[i][j] >= x:
				mask |= 1 << j
		track[mask] = i
	for i in range(lim):
		for j in range(lim):
			if i | j == match and track[i] != -1 and (track[j] != -1):
				return (track[i], track[j])
	return (-1, -1)
lo = 0
hi = 1000000000
while lo < hi - 1:
	mid = (lo + hi) / 2
	(i, j) = get_ans(mid)
	if i == -1:
		hi = mid - 1
	else:
		lo = mid
(i, j) = get_ans(hi)
if i != -1:
	print('{} {}'.format(i + 1, j + 1))
else:
	(i, j) = get_ans(lo)
	print('{} {}'.format(i + 1, j + 1))


def main():
	(N, M) = map(int, input().split())
	L = [tuple(map(int, input().split())) for _ in range(N)]
	maxi = max((max(t) for t in L)) + 1
	(mini, res) = max(((min(t), i) for (i, t) in enumerate(L)))
	res = (res, res)
	BITMASK = 1 << M
	while True:
		mid = (maxi + mini) // 2
		if mid == mini:
			break
		masks = [None] * BITMASK
		for (i, t) in enumerate(L):
			tmask = 0
			for v in t:
				tmask *= 2
				if v >= mid:
					tmask += 1
			if masks[tmask] is not None:
				continue
			masks[tmask] = i
			for k in range(BITMASK):
				if masks[k] is not None and k | tmask == BITMASK - 1:
					res = (masks[k], i)
					mini = mid = min((max(a, b) for (a, b) in zip(L[res[0]], L[res[1]])))
					break
			else:
				continue
			break
		else:
			maxi = mid
	print(res[0] + 1, res[1] + 1)
main()


import sys
from array import array
from typing import Dict, List, Tuple, TypeVar, Generic, Sequence, Union

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def main():
	(n, m) = map(int, input().split())
	mat = [array('i', map(int, input().split())) for _ in range(n)]
	bit = [1 << i for i in range(m)]
	fullbit = (1 << m) - 1

	def solve(x: int) -> Tuple[int, int]:
		dp = {sum((bit[j] for (j, y) in enumerate(mat[i]) if y >= x)): i for i in range(n)}
		keys = tuple(dp.keys())
		for i in range(len(keys)):
			for j in range(i, len(keys)):
				if keys[i] | keys[j] == fullbit:
					return (dp[keys[i]], dp[keys[j]])
		return (-1, -1)
	(ok, ng) = (0, 10 ** 9 + 1)
	(ans_i, ans_j) = (1, 1)
	while abs(ok - ng) > 1:
		mid = ok + ng >> 1
		(x, y) = solve(mid)
		if x == -1:
			ng = mid
		else:
			ok = mid
			(ans_i, ans_j) = (x + 1, y + 1)
	print(ans_i, ans_j)
main()


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from collections import defaultdict as dd
I = lambda : list(map(int, input().split()))
(n, m) = I()
l = []
an = -1
a = b = 0
for _ in range(n):
	k = I()
	l.append(k + [_ + 1])
	if an < min(k):
		a = b = _ + 1
		an = min(k)
le = an
r = 10 ** 9 + 1
while le < r:
	md = (le + r) // 2
	f = 0
	a1 = a2 = -1
	s = [0] * n
	for i in range(n):
		for j in range(m):
			if l[i][j] >= md:
				s[i] |= 1 << j
	po = 1 << m
	d = [0] * po
	for i in range(n):
		d[s[i]] = i + 1
	for i in range(1, po):
		if d[i]:
			pp = i
			while pp:
				d[pp] = d[i]
				pp = pp - 1 & i
	if d[po - 1]:
		f = 1
		a1 = a2 = d[po - 1]
	for i in range(1, po):
		if d[i] and d[po - 1 ^ i]:
			f = 1
			a1 = d[i]
			a2 = d[po - 1 ^ i]
			break
	if f:
		le = md + 1
		if md > an:
			(a, b) = (a1, a2)
			an = md
	else:
		r = md
print(a, b)


import os, sys
from io import BytesIO, IOBase

def check(mid, arr, m, n):
	ls = [[] for _ in range(1 << m)]
	for i in range(n):
		ans = 0
		for j in range(m):
			if arr[i][j] >= mid:
				ans += 1 << j
		ls[ans].append(i + 1)
	for i in range(len(ls)):
		for j in range(len(ls)):
			if len(ls[i]) and len(ls[j]) and (i | j == (1 << m) - 1):
				return (ls[i][0], ls[j][0])
	return 0

def main():
	(n, m) = map(int, input().split())
	arr = [list(map(int, input().split())) for _ in range(n)]
	(hi, lo, ind1) = (10 ** 9, 0, (1, 1))
	while hi >= lo:
		mid = (hi + lo) // 2
		ind = check(mid, arr, m, n)
		if ind:
			ind1 = ind
			lo = mid + 1
		else:
			hi = mid - 1
	print(*ind1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
a = []

def bs(a, mid, ans):
	global n, m
	can = [0 for i in range(1 << m)]
	for i in range(n):
		t = 0
		for j in range(m):
			t = t << 1 | (a[i][j] >= mid)
		can[t] = i + 1
	for i in range(1 << m):
		if not can[i]:
			continue
		for j in range(1 << m):
			if not can[j]:
				continue
			if i | j == (1 << m) - 1:
				ans[0] = can[i]
				ans[1] = can[j]
				return 1
	return 0
for i in range(n):
	p = [int(x) for x in input().split()]
	a.append(p)
l = 0
r = 100000000000
ans = [1, 1]
while l <= r:
	mid = (l + r) // 2
	if bs(a, mid, ans):
		l = mid + 1
	else:
		r = mid - 1
print(*ans)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
ans = []

def check(mid: int) -> bool:
	global ans
	dic = {}
	for i in range(n):
		bit = 0
		for j in range(m):
			if a[i][j] >= mid:
				bit += 1
			bit <<= 1
		dic[bit >> 1] = i
	for (x, idx) in dic.items():
		for (y, idy) in dic.items():
			if x | y == 2 ** m - 1:
				ans = (idx + 1, idy + 1)
				return True
	return False
le = 0
ri = int(1000000000.0)
while le <= ri:
	mid = le + ri >> 1
	if check(mid):
		le = mid + 1
	else:
		ri = mid - 1
print(ans[0], ans[1])


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append([int(i) for i in input().split()])
left = 0
right = 10 ** 9 + 1
while left < right:
	mid = (left + right) // 2
	dicta = {}
	for i in range(n):
		mask = 0
		for j in range(m):
			mask <<= 1
			if l[i][j] >= mid:
				mask += 1
		dicta[mask] = i
	ok = False
	for i in dicta:
		for j in dicta:
			if i | j == 2 ** m - 1:
				ok = True
				ans = (dicta[i] + 1, dicta[j] + 1)
				break
		if ok == True:
			break
	if ok == True:
		left = mid + 1
	else:
		right = mid
print(*ans)


from collections import defaultdict
from sys import stdin
input = stdin.readline

def check(mid, m):
	d = defaultdict(int)
	for (idx, i) in enumerate(a):
		string = ''
		for j in i:
			if j >= mid:
				string += '1'
			else:
				string += '0'
		d[int(string, 2)] = idx
	for i in d.keys():
		for j in d.keys():
			if i | j == 2 ** m - 1:
				return [d[i], d[j]]
	return []

def binarySearch(lo, hi, m):
	ans = []
	while lo < hi:
		mid = lo + (hi - lo + 1) // 2
		x = check(mid, m)
		if x:
			lo = mid
			ans = [x[0] + 1, x[1] + 1]
		else:
			hi = mid - 1
	mid = lo + (hi - lo + 1) // 2
	x = check(mid, m)
	if x:
		ans = [x[0] + 1, x[1] + 1]
	return ans
(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
print(*binarySearch(0, 10 ** 9, m))


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
SET = set()
for a in A:
	SET |= set(a)
compression_dict = {a: ind for (ind, a) in enumerate(sorted(SET))}
for i in range(n):
	A[i] = [compression_dict[a] for a in A[i]]
OK = 0
NG = len(compression_dict)
ANS = [1, 1]
B = [set()] * n
P = [2, 3, 5, 7, 11, 13, 17, 19]
Q = 1
for j in range(m):
	Q *= P[j]
import math

def ya(x):
	xr = math.ceil(math.sqrt(x))
	LIST = []
	for i in range(1, xr + 1):
		if x % i == 0:
			LIST.append(i)
			LIST.append(x // i)
	return LIST
while NG > OK + 1:
	mid = (OK + NG) // 2
	SET = set()
	for i in range(n):
		NOW = 1
		for j in range(m):
			if A[i][j] >= mid:
				NOW *= P[j]
		B[i] = NOW
		SET.add(NOW)
	flag = 0
	for s in SET:
		for l in ya(s):
			if Q // l in SET:
				flag = 1
				OK = mid
				break
		if flag:
			break
	else:
		NG = mid
SET = set()
for i in range(n):
	NOW = 1
	for j in range(m):
		if A[i][j] >= OK:
			NOW *= P[j]
	B[i] = NOW
	SET.add(NOW)
flag = 0
for i in range(n):
	for l in ya(B[i]):
		if Q // l in SET:
			ANS1 = i
			flag = 1
			break
	if flag:
		break
LIST = ya(B[i])
SET = set(LIST)
for i in range(n):
	if Q // B[i] in SET:
		ANS2 = i
print(ANS1 + 1, ANS2 + 1)


import sys
reader = (s.rstrip() for s in sys.stdin)
inp = reader.__next__
(n, m) = map(int, inp().split())
arr = tuple((tuple(map(int, inp().split())) for i in range(n)))
lower_bound = 0
upper_bound = int(1000000000.0) + 1
mask = (1 << m) - 1
ans = (0, 0)

def can_upper(mid):
	global ans
	d = dict()
	for i in range(n):
		bit = 0
		for j in range(m):
			if arr[i][j] >= mid:
				bit += 1 << j
		d[bit] = i
	keys = tuple(d.keys())
	for i in range(len(keys)):
		a1 = keys[i]
		for j in range(i, len(keys)):
			a2 = keys[j]
			if a1 | a2 == mask:
				ans = (d[a1], d[a2])
				return True
	return False
while upper_bound - lower_bound > 1:
	middle = upper_bound + lower_bound >> 1
	if can_upper(middle):
		lower_bound = middle
	else:
		upper_bound = middle
print(ans[0] + 1, ans[1] + 1)


import os
import sys
from io import BytesIO, IOBase
from collections import Counter

def check(a, mid, n, m, z):
	b = Counter()
	for i in range(n):
		c = ['0'] * m
		for j in range(m):
			if a[i][j] >= mid:
				c[j] = '1'
		zz = int(''.join(c), 2)
		b[zz] = i
	c = list(b.keys())
	lc = len(c)
	for i in range(lc):
		for j in range(i, lc):
			if c[i] | c[j] == z:
				(mi, x, y) = (10000000000, b[c[i]], b[c[j]])
				for k in range(m):
					mi = min(mi, max(a[x][k], a[y][k]))
				if mi >= mid:
					return (x, y)

def main():
	(n, m) = map(int, input().split())
	a = [list(map(int, input().split())) for _ in range(n)]
	(lo, hi, ans, y) = (0, 10 ** 9, [1, 1], (1 << m) - 1)
	while lo <= hi:
		mid = (lo + hi) // 2
		z = check(a, mid, n, m, y)
		if z:
			lo = mid + 1
			ans = [z[0] + 1, z[1] + 1]
		else:
			hi = mid - 1
	print(*ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
(N, M) = map(int, input().split())
state = [list(map(int, input().split())) for _ in range(N)]
Ans = {}
l = -1
r = 10 ** 9 + 1
while r - l > 1:
	m = (l + r) // 2
	T = {}
	for (j, S) in enumerate(state):
		bit = 0
		for (i, s) in enumerate(S):
			if s >= m:
				bit += 1 << i
		T[bit] = j
	ok = False
	for bit1 in range(1 << M):
		for bit2 in range(1 << M):
			if bit1 | bit2 == (1 << M) - 1 and bit1 in T and (bit2 in T):
				ok = True
				Ans[m] = [T[bit1], T[bit2]]
				break
		if ok:
			break
	if ok:
		l = m
	else:
		r = m
print(Ans[l][0] + 1, Ans[l][1] + 1)


def check(mid, n, m, arr):
	masks = {}
	for index in range(n):
		array = arr[index]
		x = 0
		for i in range(m):
			if array[i] >= mid:
				x ^= 1 << i
		masks[x] = index + 1
	ans = False
	(a, b) = (1, 1)
	if (1 << m) - 1 in masks.keys():
		return (True, (masks[(1 << m) - 1], masks[(1 << m) - 1]))
	for i in masks.keys():
		for j in masks.keys():
			orAns = i | j
			if orAns == (1 << m) - 1:
				if i == (1 << m) - 1 and i in masks.keys():
					a = masks[i]
					ans = True
					break
				elif j == (1 << m) - 1 and j in masks.keys():
					b = masks[j]
					ans = True
					break
				elif i in masks.keys() and j in masks.keys():
					ans = True
					(a, b) = (masks[i], masks[j])
					break
	return (ans, (a, b))

def solve(n, m, arr):
	mini = 0
	maxi = int(1000000000.0) + 5
	(i, j) = (1, 1)
	while mini <= maxi:
		mid = (mini + maxi) // 2
		(ans, res) = check(mid, n, m, arr)
		if ans:
			(i, j) = res
			mini = mid + 1
		else:
			maxi = mid - 1
	print(i, j)

def main():
	(n, m) = map(int, input().split(' '))
	arr = []
	for _ in range(n):
		x = list(map(int, input().split(' ')))
		arr.append(x)
	solve(n, m, arr)
main()


from sys import stdin, stdout
import gc
gc.disable()
input = stdin.readline
from collections import defaultdict

def check(num):
	bitmask = set()
	for i in range(n):
		b = 0
		for j in range(m):
			if arr[i][j] >= num:
				b ^= 1 << j
		bitmask.add(b)
	target = 2 ** m - 1
	for i in bitmask:
		for j in bitmask:
			if i | j == target:
				return True
	return False
(n, m) = list(map(int, input().split()))
arr = []
for _ in range(n):
	arr.append(list(map(int, input().split())))
start = 0
end = 10 ** 9
ans = -1
while start <= end:
	mid = (start + end) // 2
	if check(mid):
		ans = mid
		start = mid + 1
	else:
		end = mid - 1
bitmask = defaultdict(list)
for i in range(n):
	b = 0
	for j in range(m):
		if arr[i][j] >= ans:
			b += 1 << j
	bitmask[b].append(i + 1)
target = 2 ** m - 1
for i in bitmask:
	for j in bitmask:
		if i | j == target:
			print(bitmask[i][0], bitmask[j][0])
			exit()


MAX = 10 ** 9

def main():
	(n, m) = readIntArr()
	arrs = []
	for _ in range(n):
		arrs.append(readIntArr())

	def checkPossible(minB):
		binRepresentations = set()
		for arr in arrs:
			binRepresentations.add(convertToBinary(arr, minB))
		binList = list(binRepresentations)
		ii = jj = -1
		n = len(binList)
		for i in range(n):
			for j in range(i, n):
				if binList[i] | binList[j] == (1 << m) - 1:
					ii = binList[i]
					jj = binList[j]
		if ii != -1:
			ansi = ansj = -1
			for i in range(len(arrs)):
				b = convertToBinary(arrs[i], minB)
				if b == ii:
					ansi = i
				if b == jj:
					ansj = i
			return (ansi, ansj)
		else:
			return None

	def convertToBinary(arr, minB):
		b = 0
		for i in range(m):
			if arr[i] >= minB:
				b |= 1 << i
		return b
	minB = -1
	i = j = -1
	b = MAX
	while b > 0:
		temp = checkPossible(minB + b)
		if temp == None:
			b //= 2
		else:
			minB += b
			(i, j) = temp
	i += 1
	j += 1
	print('{} {}'.format(i, j))
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(*args):
	assert len(args) >= 2, 'makeArr args should be (default value, dimension 1, dimension 2,...'
	if len(args) == 2:
		return [args[0] for _ in range(args[1])]
	else:
		return [makeArr(args[0], *args[2:]) for _ in range(args[1])]

def queryInteractive(x, y):
	print('? {} {}'.format(x, y))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(ans))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = map(int, input().split())
A = [None] * n
(lo, hi) = (1 << 32, -1 << 32)
for i in range(n):
	A[i] = list(map(int, input().split()))
	lo = min(min(A[i]), lo)
	hi = max(max(A[i]), hi)
best = -1
ans = [-1, -1]

def possible(x):
	global best, ans
	M = [-1] * (1 << m)
	for i in range(n):
		mask = 0
		for j in range(m):
			if A[i][j] >= x:
				mask += 1 << j
		M[mask] = i
	for m0 in range(1 << m):
		if M[m0] == -1:
			continue
		for m1 in range(1 << m):
			if M[m1] == -1:
				continue
			if m0 | m1 == (1 << m) - 1:
				if best < x:
					best = x
					ans = [M[m0] + 1, M[m1] + 1]
				return True
	return False
possible(hi)
possible(lo)
while lo + 1 < hi:
	mid = (lo + hi) // 2
	if possible(mid):
		lo = mid
	else:
		hi = mid
print(*ans)


import math as mt
import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n, m) = I()
a = [I() for i in range(n)]
ans = []
lo = 0
hi = 10 ** 9

def vanguda(mid: int) -> bool:
	global ans
	f = {}
	for i in range(n):
		bi = 0
		for j in range(m):
			if a[i][j] >= mid:
				bi += 1
			bi <<= 1
		f[bi >> 1] = i
	for (aa, bb) in f.items():
		for (cc, dd) in f.items():
			if aa | cc == 2 ** m - 1:
				ans = (bb + 1, dd + 1)
				return True
	return False
while lo <= hi:
	mid = (lo + hi) // 2
	if vanguda(mid):
		lo = mid + 1
	else:
		hi = mid - 1
print(*ans)


import sys
reader = (map(int, line.split()) for line in sys.stdin)
input = reader.__next__
(n, m) = input()
arrays = []
for i in range(n):
	arrays.append(list(input()))
full = (1 << m) - 1
L = -1
R = 10 ** 9 + 1
while L + 1 < R:
	check = L + R >> 1
	masks = {}
	for (i, arr) in enumerate(arrays):
		curr = 0
		for val in arr:
			curr <<= 1
			if val >= check:
				curr |= 1
		masks[curr] = i
	isValid = False
	for k1 in masks:
		for k2 in masks:
			if k1 | k2 == full:
				ans0 = masks[k1]
				ans1 = masks[k2]
				isValid = True
				break
		if isValid:
			break
	if isValid:
		L = check
	else:
		R = check
print(ans0 + 1, ans1 + 1)


import sys, math
import io, os
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.buffer.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
mod = int(1000000000.0) + 7

def cal(x):
	l1 = set()
	d = dd(int)
	a = []
	for i in range(n):
		k = 0
		for j in range(m):
			if A[i][j] >= x:
				k += 1 << j
		l1.add(k)
		d[k] = i + 1
	l1 = list(l1)
	s = (1 << m) - 1
	for i in l1:
		for j in l1:
			if i | j == s:
				a = [d[i], d[j]]
	return a
(n, m) = mdata()
A = [mdata() for i in range(n)]
(l, r) = (0, 10 ** 9)
while l <= r:
	mid = (l + r) // 2
	if cal(mid):
		l = mid + 1
	else:
		r = mid - 1
a = cal(mid)
if a:
	outl(a)
else:
	outl(cal(mid - 1))


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
(m, n) = [int(ele) for ele in input().split()]
a = []
for i in range(m):
	a.append(list(map(int, input().split())))
(ina, mo) = (0, 10 ** 9 + 1)
(pos1, pos2) = (0, 0)
mask = (1 << n) - 1

def check(tang):
	key = set()
	dic = dict()
	for i in range(m):
		temp = 0
		for j in range(n):
			if a[i][j] >= tang:
				temp += 1 << j
		if temp in key:
			continue
		key.add(temp)
		tempk = temp
		while tempk >= 0:
			tempk &= temp
			dic[tempk] = i
			tempk -= 1
		tocheck = mask ^ temp
		if tocheck in dic:
			return (dic[tocheck], i, True)
	return (-1, -1, False)
while ina < mo - 1:
	tang = (ina + mo) // 2
	(temppos1, temppos2, status) = check(tang)
	if status:
		(pos1, pos2) = (temppos1, temppos2)
		ina = tang
	else:
		mo = tang
print(pos1 + 1, pos2 + 1)


def isPoss(n, arrs, nvals):
	masks = set()
	midx = {}
	for (pos, arr) in enumerate(arrs):
		mask = 0
		for i in range(nvals):
			if arr[i] >= n:
				mask += 1 << i
		midx[mask] = pos + 1
		masks.add(mask)
	for m1 in masks:
		for m2 in masks:
			if m1 | m2 == (1 << nvals) - 1:
				return (midx[m1], midx[m2])
	return (-1, -1)
(narr, nvals) = map(int, input().split())
arrs = []
for i in range(narr):
	arrs.append(list(map(int, input().split())))
mn = -1
mx = 10 ** 9 + 1
while mn < mx - 1:
	mid = (mn + mx) // 2
	(a, b) = isPoss(mid, arrs, nvals)
	if a != -1:
		mn = mid
	else:
		mx = mid - 1
for i in range(1, -1, -1):
	(a, b) = isPoss(mn + i, arrs, nvals)
	if a != -1:
		print(a, b)
		break


import sys
input = sys.stdin.buffer.readline
(n, m) = map(lambda x: int(x), input().split())
A = []
for _ in range(n):
	scores = list(map(lambda x: int(x), input().split()))
	A.append(scores)

def solve(n, m, A):
	ans = ()
	nstats = 2 ** m

	def judge(finalScore):
		nonlocal ans
		seen = {}
		for (i, scores) in enumerate(A):
			sta = 0
			for e in scores:
				sta = sta * 2 + (e >= finalScore)
			seen[sta] = i
		for i in range(nstats):
			for j in range(nstats):
				if i | j == nstats - 1 and i in seen and (j in seen):
					ans = (seen[i], seen[j])
					return True
		return False
	l = 0
	r = 2 ** 31 - 1
	while l < r:
		m = l + (r - l) // 2
		if not judge(m):
			r = m
		else:
			l = m + 1
	print(ans[0] + 1, ans[1] + 1)
solve(n, m, A)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
from math import inf
for _ in range(int(input()) if not True else 1):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a += [list(map(int, input().split()))]
	(alpha, omega) = (0, 10 ** 9)

	def solve(mid):
		index = [-1] * (1 << m)
		for i in range(n):
			val = 0
			for j in range(m):
				if a[i][j] >= mid:
					val += 1 << j
			index[val] = i + 1
		pos = False
		for mask in range(1 << m):
			for mask2 in range(1 << m):
				if mask | mask2 != (1 << m) - 1:
					continue
				if min(index[mask], index[mask2]) != -1:
					pos = (index[mask], index[mask2])
					break
		return pos
	while alpha < omega:
		mid = (alpha + omega + 1) // 2
		if solve(mid):
			alpha = mid
		else:
			omega = mid - 1
	print(*solve(alpha))


(n, m) = [int(i) for i in input().split(' ')]
arrmv = []
for i in range(n):
	arrmv.append([int(i) for i in input().split(' ')])
x = 0
y = int(1000000000.0 + 1)
sucls = [0, 0]
tols = []
mstr = ''
powls = [int(pow(2, i)) for i in range(10)]
twodarray = [0 for i in range(257)]
while x + 1 < y:
	mid = x + (y - x) // 2
	for (idx, ele) in enumerate(twodarray):
		twodarray[idx] = 0
	tols.clear()
	for (topidx, eletop) in enumerate(arrmv):
		tmp = 0
		for (idx, ele) in enumerate(eletop):
			if ele >= mid:
				tmp += powls[idx]
		if not twodarray[tmp]:
			twodarray[tmp] = 1
			tols.append((tmp, topidx))
	sz = len(tols)
	suc = 0
	no = int(pow(2, m))
	for i in range(sz):
		for j in range(i, sz):
			if tols[i][0] | tols[j][0] == no - 1:
				(sucls[0], sucls[1]) = (tols[i][1], tols[j][1])
				suc = 1
				break
		if suc:
			break
	if suc:
		x = mid
	else:
		y = mid
print(sucls[0] + 1, sucls[1] + 1)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
mask = (1 << m) - 1
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
lo = -1
hi = 10 ** 9 + 1
while hi - lo > 1:
	test = (hi + lo) // 2
	things = dict()
	for i in range(n):
		curr = 0
		for v in l[i]:
			curr *= 2
			if v >= test:
				curr += 1
		things[curr] = i
	works = False
	for v1 in things:
		for v2 in things:
			if v1 | v2 == mask:
				outi = things[v1]
				outj = things[v2]
				works = True
				break
		if works:
			break
	if works:
		lo = test
	else:
		hi = test
print(outi + 1, outj + 1)


import sys
input = sys.stdin.readline
max_val = 0
(n, m) = [int(item) for item in input().split()]
array = []
for i in range(n):
	line = [int(item) for item in input().split()]
	array.append(line)
	max_val = max(max_val, max(line))
good = (1 << m) - 1
l = 0
r = max_val + 1
a = 0
b = 0
while r - l > 1:
	mid = (l + r) // 2
	bit_array = dict()
	for (k, line) in enumerate(array):
		val = 0
		for (i, item) in enumerate(line):
			if item >= mid:
				val |= 1 << i
		bit_array[val] = k
	ok = False
	for key1 in bit_array.keys():
		for key2 in bit_array.keys():
			if key1 | key2 == good:
				ok = True
				i = bit_array[key1]
				j = bit_array[key2]
				break
	if ok:
		a = i
		b = j
		l = mid
	else:
		r = mid
print(a + 1, b + 1)


from sys import stdin

def solve(x: int) -> bool:
	global ans
	dp = {}
	for i in range(n):
		temp = 0
		for j in range(m):
			if a[i][j] >= x:
				temp = temp | 1 << j
		dp[temp] = i
	for (aa, bb) in dp.items():
		for (cc, dd) in dp.items():
			if aa | cc == 2 ** m - 1:
				ans = (bb + 1, dd + 1)
				return True
	return False
ans = (-1, -1)
(n, m) = map(int, stdin.readline().split())
a = []
for i in range(n):
	a.append(list(map(int, stdin.readline().split())))
(l, r) = (0, 10 ** 9)
while l <= r:
	mid = (l + r) // 2
	if solve(mid):
		l = mid + 1
	else:
		r = mid - 1
print(*ans)


hell = 1000000007
id1 = 0
id2 = 0
a = []

def check(n, m, x):
	global id1, id2
	b = [0] * (1 << m)
	idx = [0] * (1 << m)
	for i in range(n):
		mask = 0
		for j in range(m):
			if a[i][j] >= x:
				mask = mask ^ 1 << j
		b[mask] = 1
		idx[mask] = i + 1
	for i in range(1 << m):
		if b[i]:
			for j in range(1 << m):
				if b[j]:
					mask = i | j
					if mask == (1 << m) - 1:
						id1 = idx[i]
						id2 = idx[j]
						return 1
	return 0

def meowmeow321():
	(n, m) = map(int, input().split())
	for i in range(n):
		dog = [int(x) for x in input().split()]
		a.append(dog)
	lo = 0
	hi = hell
	while hi - lo > 0:
		mid = (hi + lo + 1) // 2
		if check(n, m, mid):
			lo = mid
		else:
			hi = mid - 1
	check(n, m, lo)
	print(id1, id2)
t = 1
for xxx in range(t):
	meowmeow321()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	(n, m) = RL()
	arr = []
	for _ in range(n):
		arr.append(RLL())
	res = []

	def c(num):
		nonlocal res
		dic = {}
		for i in range(n):
			now = 0
			for j in range(m):
				if arr[i][j] >= num:
					now |= 1 << j
			dic[now] = i + 1
		for (k, v) in dic.items():
			for (kk, vv) in dic.items():
				if k | kk == (1 << m) - 1:
					res = (v, vv)
					return True
		return False
	(l, r) = (0, 10 ** 9)
	while l <= r:
		mp = (l + r + 1) // 2
		now = c(mp)
		if now:
			l = mp + 1
		else:
			r = mp - 1
	print(*res)
main()


from sys import stdin, stdout
idx1 = 0
idx2 = 0
VALD = 0

def getminmax(n, m, a):
	l = 0
	h = 1000000009
	while l < h:
		mid = (l + h + 1) // 2
		exists = existsequalorbig(mid, m, a)
		if exists:
			l = mid
		else:
			h = mid - 1

def existsequalorbig(mid, m, a):
	global idx1
	global idx2
	global VALD
	abw = []
	hs = set()
	for i in range(len(a)):
		v = 0
		for j in range(m):
			if a[i][j] >= mid:
				v |= 1
			v <<= 1
		v >>= 1
		if v not in hs:
			hs.add(v)
			abw.append([i, v])
	for i in range(len(abw)):
		for j in range(i, len(abw)):
			if abw[i][1] | abw[j][1] == VALD:
				idx1 = abw[i][0]
				idx2 = abw[j][0]
				return True
	return False
nm = list(map(int, stdin.readline().split()))
n = nm[0]
m = nm[1]
VALD = int(pow(2, m) - 1)
a = []
for i in range(n):
	a.append(list(map(int, stdin.readline().split())))
getminmax(n, m, a)
stdout.write(str(idx1 + 1) + ' ' + str(idx2 + 1))


import sys
readline = sys.stdin.readline

def popcount(i):
	assert 0 <= i < 4294967296
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24
(N, M) = map(int, readline().split())
Ar = [tuple(map(int, readline().split())) for _ in range(N)]
pc = [popcount(i) for i in range(1 << M + 1)]
inf = 1 << 31
maxi = [0] * (1 << M)
for i in range(N):
	a = Ar[i]
	dp = [0] * (1 << M)
	for S in range(1, 1 << M):
		p = pc[S]
		if p == 1:
			k = S.bit_length() - 1
			dp[S] = a[k]
		else:
			dp[S] = min(dp[-S & S], dp[S ^ -S & S])
		maxi[S] = max(maxi[S], dp[S])
for i in range(M):
	for j in range(1 << M):
		if not j & 1 << i:
			maxi[j] = max(maxi[j], maxi[j | 1 << i])
D = (1 << M) - 1
ans = maxi[D]
(aS, bS) = (D, D)
for S in range(1 << M):
	candi = min(maxi[S], maxi[D ^ S])
	if candi > ans:
		(aS, bS) = (S, D ^ S)
		ans = candi
Ans = [None] * 2
pre = False
fro = False
for i in range(N):
	a = Ar[i]
	resa = inf
	resb = inf
	for j in range(M):
		if 1 << j & aS:
			resa = min(resa, a[j])
		else:
			resb = min(resb, a[j])
	if resa >= ans:
		pre = True
		Ans[0] = i + 1
	if resb >= ans:
		fro = True
		Ans[1] = i + 1
	if pre and fro:
		break
print(*Ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(10)]
pp = [0] * 10

def SieveOfEratosthenes(n=10):
	p = 2
	c = 0
	while p * p <= n:
		if prime[p] == True:
			c += 1
			for i in range(p, n + 1, p):
				pp[i] += 1
				prime[i] = False
		p += 1

def binarySearch(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = arr[n - 1]
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] >= key:
			res = arr[mid]
			right = mid - 1
		else:
			left = mid + 1
	return res

def binarySearch1(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = arr[0]
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] > key:
			right = mid - 1
		else:
			res = arr[mid]
			left = mid + 1
	return res
(n, m) = map(int, input().split())
l = []
pm = 2 ** m - 1
for i in range(n):
	l.append(list(map(int, input().split())))

def find(x):
	s = set()
	d = defaultdict(int)
	for i in range(n):
		a = ''
		for j in range(m):
			if l[i][j] >= x:
				a += '1'
			else:
				a += '0'
		d[int(a, 2)] = i
		s.add(int(a, 2))
	s = list(s)
	for i in range(len(s)):
		for j in range(i, len(s)):
			if s[i] | s[j] == pm:
				return [d[s[i]] + 1, d[s[j]] + 1]
	return [-1, -1]
st = 0
end = 10 ** 9
ans = (0, 0)
while st <= end:
	mid = (st + end) // 2
	s = find(mid)
	if s[0] != -1:
		ans = s
		st = mid + 1
	else:
		end = mid - 1
print(*ans)


def check(x: int) -> (int, int):
	vis = {}
	for (i, array) in enumerate(a):
		t = 0
		for (j, val) in enumerate(array):
			if val >= x:
				t |= 1 << j
		vis[t] = i
	if (1 << m) - 1 in vis:
		return (vis[(1 << m) - 1], vis[(1 << m) - 1])
	for i in range(1, (1 << m) - 1):
		for j in range(1, (1 << m) - 1):
			if i in vis and j in vis and (i | j == (1 << m) - 1):
				return (vis[i], vis[j])
	return (-1, -1)
(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
l = 0
r = int(1000000000.0)
while l <= r:
	mid = l + r >> 1
	if check(mid) != (-1, -1):
		l = mid + 1
	else:
		r = mid - 1
ans = check(r)
print('%d %d' % (ans[0] + 1, ans[1] + 1))


import sys
input = sys.stdin.readline

def main():
	(n, m) = map(int, input().split())
	a = []
	for _ in [0] * n:
		a.append(list(map(int, input().split())))
	ok = 0
	ng = 10 ** 9 + 1
	judge = pow(2, m) - 1
	dg = 1000
	while ng - ok > 1:
		mid = (ng + ok) // 2
		tank = set()
		for i in range(n):
			r = 0
			for j in range(m):
				r *= 2
				if a[i][j] >= mid:
					r += 1
			tank.add(r)
		for p in tank:
			for q in tank:
				if p | q == judge:
					ok = mid
					break
		if ok != mid:
			ng = mid
	tank = set()
	res = []
	for i in range(n):
		r = 0
		for j in range(m):
			r *= 2
			if a[i][j] >= ok:
				r += 1
		if not r in tank:
			res.append(i * dg + r)
		tank.add(r)
	for p in res:
		for q in res:
			if p % dg | q % dg == judge:
				print(p // dg + 1, q // dg + 1)
				return
main()


import os, sys, atexit
from io import BytesIO, StringIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
_OUTPUT_BUFFER = StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
(n, m) = map(int, input().split())
arr = [0] * n
for i in range(n):
	temp = list(map(int, input().split()))
	arr[i] = temp
x = 1
N = 2 ** m - 1
lo = 1
hi = 1000000009
ind = [0, 0]
while 1:
	l = {}
	freq = [0] * 2 ** m
	for i in range(n):
		an = 0
		for j in range(m):
			if arr[i][j] >= x:
				an += 2 ** (m - j - 1)
		if freq[an] == 0:
			l[i] = an
		freq[an] = 1
	ch = 0
	for (k1, v1) in l.items():
		for (k2, v2) in l.items():
			if v1 | v2 == N:
				ch = 1
				ind[0] = k1 + 1
				ind[1] = k2 + 1
				break
		if ch:
			break
	if ch:
		lo = x
		x = x * 2
	else:
		hi = x
		break
ans = lo
while hi - lo > 1:
	x = (lo + hi) // 2
	l = {}
	freq = [0] * 2 ** m
	for i in range(n):
		an = 0
		for j in range(m):
			if arr[i][j] >= x:
				an += 2 ** (m - j - 1)
		if freq[an] == 0:
			l[i] = an
		freq[an] = 1
	ch = 0
	for (k1, v1) in l.items():
		for (k2, v2) in l.items():
			if v1 | v2 == N:
				ch = 1
				ind[0] = k1 + 1
				ind[1] = k2 + 1
				break
		if ch:
			break
	if ch:
		lo = x
	else:
		hi = x
ans = lo
if ind[0] == 0:
	print('1 1')
else:
	print(*ind)


import os
import sys
from bisect import bisect_right, bisect_left
from collections import Counter
from io import BytesIO, IOBase
from math import gcd, inf, sqrt, ceil

def lcm(a, b):
	return a * b // gcd(a, b)

def sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def getFactorization(x):
	ret = Counter()
	while x != 1:
		ret[spf[x]] += 1
		x = x // spf[x]
	return ret

def printDivisors(n):
	i = 2
	z = [1, n]
	while i <= sqrt(n):
		if n % i == 0:
			if n / i == i:
				z.append(i)
			else:
				z.append(i)
				z.append(n // i)
		i = i + 1
	return z

def create(n, x, f):
	pq = len(bin(n)[2:])
	if f == 0:
		tt = min
	else:
		tt = max
	dp = [[inf] * n for _ in range(pq)]
	dp[0] = x
	for i in range(1, pq):
		for j in range(n - (1 << i) + 1):
			dp[i][j] = tt(dp[i - 1][j], dp[i - 1][j + (1 << i - 1)])
	return dp

def enquiry(l, r, dp, f):
	if l > r:
		return inf if not f else -inf
	if f == 1:
		tt = max
	else:
		tt = min
	pq1 = len(bin(r - l + 1)[2:]) - 1
	return tt(dp[pq1][l], dp[pq1][r - (1 << pq1) + 1])

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	x = []
	for i in range(2, n + 1):
		if prime[i]:
			x.append(i)
	return x

def main():

	def check(mid):
		x = set()
		d = dict()
		for i in range(n):
			s = 0
			for j in range(m):
				if matx[i][j] >= mid:
					s ^= 1 << j
			d[s] = i
			x.add(s)
		for i in x:
			for j in x:
				if i | j == (1 << m) - 1:
					return (True, d[i], d[j])
		return (False, 0)
	(n, m) = map(int, input().split())
	matx = [[int(x) for x in input().split()] for j in range(n)]
	do = 0
	up = 10 ** 9
	while up >= do:
		mid = (up + do) // 2
		tt = check(mid)
		if tt[0]:
			an = (tt[1] + 1, tt[2] + 1)
			do = mid + 1
		else:
			up = mid - 1
	print(*an)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
left = 0
right = 10 ** 9 + 1
ans = (0, 0)
while left < right:
	mid = (left + right) // 2
	masks = {}
	for i in range(n):
		mask = 0
		for j in a[i]:
			mask <<= 1
			if j >= mid:
				mask += 1
		masks[mask] = i
	ok = False
	for m1 in masks:
		for m2 in masks:
			if m1 | m2 == (1 << m) - 1:
				ok = True
				ans = (masks[m1] + 1, masks[m2] + 1)
				break
		if ok:
			break
	if ok:
		left = mid + 1
	else:
		right = mid
print(ans[0], ans[1])