/*
AizuOnline A1215
Title
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
#include <string.h>
//#include <float.h>
//#include <math.h>
#include <limits.h>
//Global data section
#define STRINGLEN 1000000
#define SEARCHLEN 50
#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
char s[STRINGLEN+1];
char sc[SEARCHLEN+1];
char *find;
int minret; //=> grobal
char *find11;
char aaa[1000];
char bbb[1000];
//
void print_find()
{
  int i;

  for(i=0;i<=minret;i++)
    printf("%c",find[i]);
  printf("\n");

}
int my_strstr(char *s1,char *s2)
{
  //int minret //g
  int mincnt,ret;


  extern int my_strstr_sub(char *,char *);
  
  ret=my_strstr_sub(s1,s2);
  minret=ret;mincnt=1;
  memcpy(find,find11,ret+1);
  //print_find();

  while((ret=my_strstr_sub(NULL,s2)) > 0)
  {
#ifdef DEBUG2
    printf("ret|%d\n",ret);
#endif
    if(ret == minret)
      mincnt++;
    else if (ret < minret)
      {
	memcpy(find,find11,ret+1);
	minret=ret;
	mincnt=1;
      }
  }
  return(mincnt);
  
}
int my_strstr_sub(char * s1,char * s2)
{
  int s_len;
  int i;
  int maxret;
  int minret; 
  char *s_len_p;
  static char *s11;
  

  if(s1)
    s11=s1;
#ifdef DEBUG2
  for(i=0;i<30;i++)
    printf("%c",s11[i]);
  printf(":");
  for(i=0;i<3;i++)
    printf("%c",s2[i]);
  printf("\n");

#endif  
  maxret=0;minret=INT_MAX;
  //printf("SC* %d\n",strlen(s2));
  for(i=0;i<strlen(s2);i++)
    {
      s_len_p = strchr(s11,s2[i]);
      
      if(NULL==s_len_p)  //not found
	{
	return(-1);
	}
      else
	{
	  s_len = s_len_p - s11;
	  //printf("NF*%d\n",s_len);
 	  maxret = max(maxret,s_len);
	  if(s_len!=0)         //except zero
	    minret = min(minret,s_len);
	}
    }
#ifdef DEBUG2
  printf("mm:%d %d\n",minret,maxret);
#endif
  memcpy(find11,s11,maxret+1);
  s11 += minret;
  return(maxret);
}

main()
{
  char *sptr;
  int ret,i;
  char c;
  char s1[10];
    

  find11=aaa;
  find=bbb;
  sptr=s;
  while(1)
    {
      while(EOF!=scanf("%c",sptr))
	{
	  if(sptr > s && sptr[0] == '\n' && c == '\n')
	    break;
	  c=sptr[0];
	  if(sptr[0] != '\n') 
	    sptr++;
	}
      if(sptr==s)
	break;
      sptr[0]='\0';
      scanf("%s ",sc);
     
      //if(EOF==scanf("%s" ,s1))
      //break;


 
#ifdef DEBUG2
      printf(">%s\n",s);
      printf(">>%s\n",sc);	
#endif
      ret=my_strstr(s,sc);
      printf("%d\n",ret);
      //printf("mr%d\n",minret);
      
      if(ret)
	{
	  print_find();
	}
      sptr=s;
      memset(aaa,0,1000);
      memset(bbb,0,1000);
    }
return(0);
}