You are given two string S and T. Find the maximal length of some prefix of the string S which occurs in strings T as subsequence.

Input
The first line contains string S.
The second line contains string T.
Both strings consist of lowecase Latin letters.

Output
Output one integer - answer to the question.

Constraints
1 ≤ length of S, T ≤ 10^6

SAMPLE INPUT
digger
biggerdiagram

SAMPLE OUTPUT
3
def search(pat,txt):
	m = len(pat)
	n = len(txt)
	i = 0
	j = 0
	count = 0
	while i <n:
		if pat[j] == txt[i]:
			i+=1
			j+=1
			count+=1
		if j==m:
			return count
			
		else:
			if i<n and pat[j] != txt[i]:
				i+=1
	return count



pat = raw_input()
txt = raw_input()
print search(pat,txt)