#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include<string>
#include<vector>
#define N 1000010
using namespace std;
int next[N];
char p[N];
char s[N];
int n,m;
void getNext(){
for(int i = 0; i < n; ++i)next[i] = -1;
int j = 0, k = -1;
while(j < m - 1){
if(k == -1 || p[k] == p[j]){
++k;
++j;
if(p[k] != p[j])
next[j] = k;
else
next[j] = next[k];
}
else{
k = next[k];
}
}
}
int KMP(){
int i = 0,j = 0;
while(i < n && j < m){
if(j == -1 || s[i] == p[j]){
++i;
++j;
}
else{
j = next[j];
}
}
printf("i: %d ,j : %d \n",i,j);
if( j == m) return i - j;
else
return -1;
}
int main(){
while(~scanf("%s%s",&s,&p)){
n = strlen(s);
m = strlen(p);
getNext();
printf("%d\n",KMP());
}
return 0;
}