text

Time limit: 0.5s Memory limit: 64MB Input: Output:

Task

Ancient viking people carved stories on stone using their own symbols. Björn found NN versions of the same story and he already converted them to texts containing only the lowercase letters a-z. The texts are indexed from 0 to N1N-1, let's denote them with S0,S1,SN1S_0, S_1, \ldots S_{N-1}. All the texts have the same length KK, but they might differ on some positions.

Now Björn wants to know which is the original version of the story, because he thinks that the others are just mutated copies of it. He suspects that the original text is the one that has the minimal average distance from all the others. We define the distance between two texts as the number of positions where they differ.

More formally, the distance between two texts SiS_i and SjS_j denoted by dist(Si,Sj)dist(S_i, S_j) is the number of different kk indices, for which 0kK10 \leq k \leq K-1 and Si[k]Sj[k]S_i[k] \neq S_j[k]. We are looking for the text SorigS_{orig} for which the value avgdist(Si)avgdist(S_{i}) = 1N1j=0N1dist(Si,Sj)\frac{1}{N-1} \sum_{j=0}^{N-1}{dist(S_{i}, S_j)} is minimal. (Note that dist(Si,Si)=0dist(S_i, S_i) = 0). If there are multiple texts with the same average distance from the others, you should choose the one which has the smallest index of those.

Can you help Björn to determine which one is the original text?

Input

The first line contains two integers NN and KK (1N,K1051 \le N, K \le 10^5), (1NK1061 \le N * K \le 10^6). The following NN lines each contain a string SiS_i of length KK containing only lowercase English letters abc...z.

For tests worth 44 points, N=2N = 2.

For tests worth 1111 more points, N=3N = 3.

For tests worth 2121 more points, 1N,K1001 \le N, K \le 100.

For tests worth 2525 more points, SiS_i consists of only letters aa and bb.

Output

You need to write a single line with an integer between 00 and N1N-1, the index of the original text. If there are multiple possible solutions, print the one with the smallest index.

Example 1

stdin

3 3
aab
aba
aaa

stdout

2

Example 2

stdin

5 7
abcdefg
abcdefh
abcdefh
abcdefi
abcdefj

stdout

1

Explanation

In the first sample case,

  • avgdist(aab)avgdist(aab) = 12(dist(aab,aba)\frac{1}{2}(dist(aab, aba) + dist(aab, aaa)) = 12(2+1)\frac{1}{2}(2 + 1) = 1.51.5
  • avgdist(aba)avgdist(aba) = 12(dist(aba,aab)\frac{1}{2}(dist(aba, aab) + dist(aba, aaa)) = 12(2+1)\frac{1}{2}(2 + 1) = 1.51.5
  • avgdist(aaa)avgdist(aaa) = 12(dist(aaa,aab)\frac{1}{2}(dist(aaa, aab) + dist(aaa, aba)) = 12(1+1)\frac{1}{2}(1 + 1) = 11

So, the last text has the minimal average distance from the others, hence the answer is its index, which is 2.

In the second sample case, abcdefh has an average distance of 0.750.75 while the other texts have an average distance of 11, so the solution is the index of the first occurrence of abcdefh, which is 1.

Log in or sign up to be able to send submissions!