#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int N,M;
cin>>N>>M;
string *str = new string[M];
for(int i=0;i<M;i++)
cin>>str[i];
vector<vector<char> > transStr(N,vector<char>(M));
for(int i=0;i<N;i++)
{
for(int j=0;j<M;j++)
{
transStr[i][j] = str[j][i];
}
}
for(int i=0;i<N;i++)
{
sort(transStr[i].begin(),transStr[i].end());
}
vector<char> strTemp=transStr[0];
int index = -1;
for(int i=1;i<N;i++)
{
int count_0=0;
int count_m=0;
for(int j=0;j<M;j++)
{
if(strTemp[j]>transStr[i][j])
{
count_m++;
}
if(strTemp[j]<transStr[i][j])
{
count_0++;
}
}
if(count_0<count_m)
{
strTemp=transStr[i];
index = i;
}
else if(count_0<count_m)
index = 0;
else
index = -1;
}
cout<<index;
return 0;
}