/*Shovkoplyas Grigory in the house*/
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<vector>
#include<set>
#include<map>
using namespace std;

#define name "lyrics"

char s[1000][1001];

int main()
{
  freopen(name".in", "r", stdin);
  freopen(name".out", "w", stdout);
  int n, m;
  scanf("%d %d\n", &n, &m);
  for(int i = 0; i < n; i++)
    gets(s[i]), assert(strlen(s[i]) <= 100);
  int k = 1000;
  for(int i = 0; i < n; i++)
  {
    k = min(k, (int)strlen(s[i]));
    if(i > m)
    {
      int a = strlen(s[i]);
      int b = strlen(s[i - m]);
      int j = 0;
      while(j < min(a, b) && s[i][a - j - 1] == s[i - m][b - j - 1])
        j++;
      k = min(k, j);
    }
  }
  printf("%d\n", k);
  return 0;
}

                                    

