Rats

아직 제출이 없습니다시간 제한0.75초메모리 제한256 MB

문제

You are given an infinite line covered with a periodically repeating string AA (there are infinitely many concatenated copies of the string AA in the line). The line doesn't have a beginning or an end. You are given a set SS with MM strings. You need to build new string BB as concatanation of strings from SS. String BB must satisfy the following conditions:

  • After covering a new empty infinite line with infinitely many concatenations of the string BB, the line should be identical with string AA
  • In case there are several valid strings BB or several valid constructions of the string BB, you should choose BB and its construction which minimize number of strings used from SS.

You can use the same string from SS several times, but every time you count it as new string. You can concatenate all strings in any order, but you are not allowed to change the order of letters in the string. In case there is no proper way to build some string BB, print 1-1.

입력

  • The first line contains string AA (1A500)(1\leq |A| \leq 500).
  • The second line contains the integer MM (1M105)(1 \leq M \leq 10^5), number of strings in set SS.
  • Each of next MM lines contains one string from SS, ii-th line contains string L_iL\_i (1L_iA)(1 \leq |L\_i| \leq |A|). Sum of lengths of strings from set SS is smaller than 10610^6 (_i=1ML_i106)(\sum\_{i=1}^{M} |L\_i| \leq 10^6).

출력

Print one integer --- minimum number of string instances from SS needed to build string BB.

힌트

You can use one string "b" and two strings "a", to build BB = "aba":

  • ...baabaabaabaa...
  • .....abaabaabaaba...