Infinite String Search
You are given a string , and a pattern .
Define the sequence as follows:
where we define .
For example, if , we obtain the sequence
If we assume the sequence goes on forever, we obtain an infinite string. Your task is to find the first position where the pattern appears in this infinite string generated from .
Input
The first line of input contains the string ().
The second line of input contains the pattern ().
Output
Output a single integer , the 0-based index of the first position where the pattern appears in the generated string. If the pattern never appears in the string, output .
Samples
Sample 1
Input
01 00
Output
5
The first few characters of the generated string are:
The pattern occurs at position 5.
Sample 2
Input
01 000
Output
-1
It's possible to prove that the pattern never occurs in the generated string.
Sample 3
Input
101101011 10111
Output
50