#include <iostream>
#include <string>
using namespace std;
//BF算法(暴力匹配算法)
int BF(string s1, string s2, int pos)
{
int i = pos - 1;
int j = 0;
while(i < s1.length() && j < s2.length()) //若i和j都大于字符串的长度就结束循环
{
if(s1[i] == s2[j])
{
i++;
j++;
}
else
{
i = i - j + 2;
j = 1;
}
}
if(j >= s2.length())
return i - s2.length(); //返回的是第一次匹配到的字符的下标
return 0;
}
int main()
{
string s1 = "abcdabcdefg";
string s2 = "abcde";
int pos;
cin >> pos; //输入s1开始匹配的位置
cout << BF(s1, s2, pos);
return 0;
}