#include <stdio.h>
#include <stdlib.h>

#define MAX 10000

int main()
{
  FILE *f,*p;
  int j,brojRec=1,i,k,n,done=0;
  char s[MAX];
  char c;
  
  scanf("%d%d",&k,&n);
  
  if(k<0 || n<0)
  {
    printf("-1");
    return 1;
  }
  
  f=fopen("ulaz.txt","r");
  p=fopen("izlaz.txt","w");
  
  if(f==NULL || p==NULL)
  {
    printf("-1");
    return 1;
  }
  
  while((c=fgetc(f))!=EOF)
  {
    if(c==' ' || c=='\n')
    {
      brojRec++;
      done=0;
    }
    
    if(brojRec==k && done==0)
    {
      for(j=1;(c=fgetc(f))!=' ' && c!=EOF && c!='\n';j++)
      {
	if(j%n!=0)
	{
	  fputc(c,p);
	}
      }
      done++;   
      fprintf(p," ");
      brojRec=0;
      if(c==' ' || c=='\n')
      {
	brojRec++;
      }
    }
  }
  
  fclose(f);
  fclose(p);
  
  return 0;
}
      
