Problem F: String Problem F

Problem F: String Problem F

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1922  Solved: 417
[Submit][Status][Web Board]

Description

Given a string of which the first half is generated by applying a substitution cipher on the second half and the second half may lost some characters from the tail. You are now required to calculate the minimal possible length of the second half of the string.

Input

The first line is the code table for the substitution cipher, which contains 26 letters representing the encrypted letter for each letter in lexicographical order. 

The second line is \(S \ \ (1\leq |s| \leq 5*10^5)\).

Output

One integer, indicating the minimal possible length of the second half.

Sample Input

b c d e f g h i j k l m n o p q r s t u v w x y z a
bcdeabc

Sample Output

4

HINT

[Submit][Status]