#AGC007F. [AGC007F] Shik and Copying String

[AGC007F] Shik and Copying String

Score : 15001500 points

Problem Statement

Shik's job is very boring. At day 00, his boss gives him a string S0S_0 of length NN which consists of only lowercase English letters. In the ii-th day after day 00, Shik's job is to copy the string Si1S_{i-1} to a string SiS_i. We denote the jj-th letter of SiS_i as Si[j]S_i[j].

Shik is inexperienced in this job. In each day, when he is copying letters one by one from the first letter to the last letter, he would make mistakes. That is, he sometimes accidentally writes down the same letter that he wrote previously instead of the correct one. More specifically, Si[j]S_i[j] is equal to either Si1[j]S_{i-1}[j] or Si[j1]S_{i}[j-1]. (Note that Si[1]S_i[1] always equals to Si1[1]S_{i-1}[1].)

You are given the string S0S_0 and another string TT. Please determine the smallest integer ii such that SiS_i could be equal to TT. If no such ii exists, please print -1.

Constraints

  • 1N1,000,0001 \leq N \leq 1,000,000
  • The lengths of S0S_0 and TT are both NN.
  • Both S0S_0 and TT consist of lowercase English letters.

Input

The input is given from Standard Input in the following format:

NN

S0S_0

TT

Output

Print the smallest integer ii such that SiS_i could be equal to TT. If no such ii exists, print -1 instead.

5
abcde
aaacc
2

S0S_0 = abcde, S1S_1 = aaccc and S2S_2 = aaacc is a possible sequence such that S2=TS_2 = T.

5
abcde
abcde
0
4
acaa
aaca
2
5
abcde
bbbbb
-1