#include <bits/stdc++.h>
using namespace std;
/*旋转hash(Rabin-Karp算法)实现字符串匹配
*基本原理:把每个字符当做数字对待,这样字符串就是一串数字,
把字符串比较操作转化为数字比较操作*/
/*由于hash冲突存在,需要一个函数判断两个字符串确实相等*/
const int factor = 41;
int StrMatch(string source,string pattern){
int len1 = source.size();
int len2 = pattern.size();
assert(len2 <= len1);
int subHash = 0,curHash = 0;
for(auto i = 0;i < len2;++i){
subHash += (int)pattern[i] * factor;
curHash += (int)source[i] * factor;
}
/*先比较pat和src的第一个子串*/
if(curHash == subHash && source.substr(0,len2) == pattern)
return 0;
/*剩下子串开始递推*/
for(auto i = 1; i <= len1 - len2;++i){
curHash = curHash - (int)source[i-1] * factor + (int)source[i + len2 - 1] * factor;
if(curHash == subHash && source.substr(i,len2) == pattern)
return i;
}
return -1;
}
int main(){
string s,p;
while(cin >> s >> p){
cout<<StrMatch(s,p)<<endl;
}
return 0;
}