#P1288D. Minimax Problem

    ID: 1868 Type: RemoteJudge 5000ms 512MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>binary searchbitmasksdp*2000

Minimax Problem

No submission language available for this problem.

Description

You are given nn arrays a1a_1, a2a_2, ..., ana_n; each array consists of exactly mm integers. We denote the yy-th element of the xx-th array as ax,ya_{x, y}.

You have to choose two arrays aia_i and aja_j (1i,jn1 \le i, j \le n, it is possible that i=ji = j). After that, you will obtain a new array bb consisting of mm integers, such that for every k[1,m]k \in [1, m] bk=max(ai,k,aj,k)b_k = \max(a_{i, k}, a_{j, k}).

Your goal is to choose ii and jj so that the value of mink=1mbk\min \limits_{k = 1}^{m} b_k is maximum possible.

The first line contains two integers nn and mm (1n31051 \le n \le 3 \cdot 10^5, 1m81 \le m \le 8) — the number of arrays and the number of elements in each array, respectively.

Then nn lines follow, the xx-th line contains the array axa_x represented by mm integers ax,1a_{x, 1}, ax,2a_{x, 2}, ..., ax,ma_{x, m} (0ax,y1090 \le a_{x, y} \le 10^9).

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

Input

The first line contains two integers nn and mm (1n31051 \le n \le 3 \cdot 10^5, 1m81 \le m \le 8) — the number of arrays and the number of elements in each array, respectively.

Then nn lines follow, the xx-th line contains the array axa_x represented by mm integers ax,1a_{x, 1}, ax,2a_{x, 2}, ..., ax,ma_{x, m} (0ax,y1090 \le a_{x, y} \le 10^9).

Output

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

Samples

Sample Input 1

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

Sample Output 1

1 5