Kaguya has heard that Miyuki has trouble singing the academy anthem. Upon deeper inspection, Kaguya suspects that the academy anthem has certain substrings that trip Miyuki up.
Given the academy anthem
Constraints
All strings only contain lowercase letters.
There are no subtasks in this problem. Each correct test case will award marks.
Input Specification
The first line contains the string
The next line contains an integer
Each of the next
Output Specification
Output -1
if there are fewer than
Sample Input 1
Copy
abacabadabacaba
4
a 7
e 3
bac 2
abada 1
Sample Output 1
Copy
13
-1
10
5
Comments