Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.

Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya".

Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey.

It is guaranteed that the word p can be obtained by removing the letters from word t.


-----Input-----

The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t.

Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct).


-----Output-----

Print a single integer number, the maximum number of letters that Nastya can remove.


-----Examples-----
Input
ababcba
abb
5 3 4 1 7 6 2

Output
3
Input
bbbabb
bb
1 6 3 4 2 5

Output
4


-----Note-----

In the first sample test sequence of removing made by Nastya looks like this:

"ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" 

Nastya can not continue, because it is impossible to get word "abb" from word "ababcba".

So, Nastya will remove only three letters.

Difficulty: MEDIUM_HARD

Solutions:
t = list(input())
p = list(input())
s = input().split()
v = [0] * len(s)
for i in range(len(s)):
	v[i] = int(s[i])
(l, r) = (0, len(t))
while r - l > 1:
	m = (l + r) // 2
	t1 = t[:]
	for i in range(m):
		t1[v[i] - 1] = '*'
	(i, j) = (0, 0)
	while j < len(t1) and i < len(p):
		if p[i] == t1[j]:
			i += 1
		j += 1
	if i == len(p):
		l = m
	else:
		r = m
print(l)


import sys

def removeat(string, indexes):
	return [c for (i, c) in enumerate(string) if i not in indexes]

def contains(string, what):
	if not len(what):
		return True
	if not len(string):
		return False
	checked = 0
	for c in string:
		if what[checked] == c:
			checked += 1
			if checked == len(what):
				break
	return checked == len(what)
string = list(input())
what = list(input())
indexes = [i - 1 for i in map(int, input().split())]
first = 0
last = len(indexes) - 1
while first < last:
	midpoint = first + (last - first) // 2 + (last - first) % 2
	if contains(removeat(string, set(indexes[:midpoint])), what):
		first = midpoint
	else:
		last = midpoint - 1
print(first)


s = input()
p = input()
a = list(map(int, input().split()))
a_inds = [0] * (len(s) + 1)
for i in range(len(a)):
	a_inds[a[i]] = i
l = -1
r = len(s)

def check_answer(ans):
	i = 0
	j = 0
	while i < len(s) and j < len(p):
		if a_inds[i + 1] >= ans and s[i] == p[j]:
			j += 1
		i += 1
	return j == len(p)
while l < r - 1:
	m = (l + r) // 2
	if check_answer(m):
		l = m
	else:
		r = m
print(r - 1)


import heapq
from bisect import bisect_left, bisect_right
from itertools import accumulate

def is_substr(fw, tw, seq):
	(i, j) = (0, 0)
	while i < len(fw) and j < len(tw):
		if i in seq:
			i += 1
		elif fw[i] == tw[j]:
			(i, j) = (i + 1, j + 1)
		else:
			i += 1
	return j == len(tw)
R = lambda : map(int, input().split())
(fw, tw) = (input(), input())
seq = [i - 1 for i in list(R())]
(l, r) = (0, len(seq) - 1)
(m, res) = (0, 0)
while l <= r:
	m = (l + r) // 2
	if is_substr(fw, tw, set(seq[:m])):
		res = max(res, m)
		l = m + 1
	else:
		r = m - 1
print(res)


p = input()
t = input()
arr = [int(i) - 1 for i in input().split(' ')]

def check(mid):
	l = list(p)
	for i in range(mid + 1):
		l[arr[i]] = ' '
	found = 0
	i = 0
	while found < len(t) and i < len(arr):
		if l[i] is t[found]:
			found += 1
		i += 1
	return found == len(t)
(l, r) = (-1, len(arr) - 1)
while l < r:
	mid = (l + r + 1) // 2
	if check(mid):
		l = mid
	else:
		r = mid - 1
print(l + 1)


def subset(S, s):
	i = 0
	j = 0
	while i < len(S) and j < len(s):
		if S[i] == s[j]:
			i += 1
			j += 1
		else:
			i += 1
	if j == len(s):
		return True
	return False
n = input()
a = input()
arr = [int(x) - 1 for x in input().split()]
new = []
l = 0
r = len(n)
while l < r:
	mid = (l + r + 1) // 2
	sa = arr[:mid]
	new = list(n)
	for i in sa:
		new[i] = ''
	if subset(''.join(new), a):
		l = mid
	else:
		r = mid - 1
print(r)


def ok(n):
	mark = set()
	global a
	for i in range(n):
		mark.add(a[i] - 1)
	one = 0
	two = 0
	while one < len(p) and two < len(t):
		if two in mark:
			two += 1
		elif p[one] == t[two]:
			one += 1
			two += 1
		else:
			two += 1
	return one == len(p)
t = input()
p = input()
a = list(map(int, input().split()))
l = 0
r = len(t)
ans = -1
while l <= r:
	mid = (l + r) // 2
	if ok(mid):
		ans = mid
		l = mid + 1
	else:
		r = mid - 1
print(ans)


def f(ind):
	global t, p, a
	g = t.copy()
	c = p.copy()
	b = []
	for i in range(ind + 1):
		g[a[i] - 1] = '0'
	for i in range(len(g)):
		if g[i] != '0':
			b.append(g[i])
	symbol = 0
	for i in range(len(b)):
		if b[i] == c[symbol]:
			symbol += 1
		if symbol == len(c):
			return True
	return False
t = list(input())
p = list(input())
a = list(map(int, input().split()))
if len(t) == len(p) or f(0) == False:
	print(0)
else:
	L = 0
	R = len(a)
	while R - L > 1:
		d = (L + R) // 2
		if f(d):
			L = d
		else:
			R = d
	print(L + 1)


s1 = input()
s2 = input()
rs = list(map(int, input().split()))

def is_in(big, little):
	(i, j) = (0, 0)
	matched = 0
	while i < len(big) and j < len(little):
		if big[i] == little[j]:
			matched += 1
			i += 1
			j += 1
		else:
			i += 1
	if matched < len(little):
		return False
	return True

def gen_st(mid):
	global s1, s2, rs
	cs = set(rs[:mid])
	n = []
	for i in range(len(s1)):
		if i + 1 in cs:
			continue
		n.append(s1[i])
	return is_in(''.join(n), s2)
start = 0
end = len(rs)
weird = False
while start < end:
	mid = (start + end) // 2
	if gen_st(mid):
		start = mid
		if start == end - 1:
			weird = True
			if gen_st(end):
				print(end)
				break
			else:
				print(start)
				break
	else:
		end = mid - 1
	if not weird and start == end:
		print(start)


import sys, os, io
from math import log, gcd, ceil
from collections import defaultdict as dd, deque, Counter
from heapq import heappush, heappop
from sys import stdin
from bisect import bisect_left, bisect_right
import math

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
mod = 998244353
t = 1

def check(moves):
	l = list(s)
	for i in range(moves):
		l[p[i] - 1] = '.'
	ptrt = 0
	ptrl = 0
	while ptrt < len(t) and ptrl < len(l):
		if l[ptrl] == t[ptrt]:
			ptrl += 1
			ptrt += 1
		else:
			ptrl += 1
	if ptrt == len(t):
		return 1
	return 0
for _ in range(t):
	s = si()
	t = si()
	p = li()
	n = len(s)
	low = 0
	high = n
	ans = 0
	while low <= high:
		mid = (high + low) // 2
		if check(mid):
			ans = mid
			low = mid + 1
		else:
			high = mid - 1
	print(ans)


t = input()
p = input()
a = [i - 1 for i in list(map(int, input().split()))]
min1 = 0
max1 = len(t)
while max1 - min1 > 1:
	med = min1 + (max1 - min1) // 2
	j = 0
	d = list(t)
	for i in range(med):
		d[a[i]] = ''
	for i in range(len(t)):
		if d[i] == p[j]:
			j += 1
			if j == len(p):
				min1 = med
				break
	if j != len(p):
		max1 = med
print(min1)


s = input()
t = input()
arr = list(map(int, input().split()))
l = 0
r = len(arr) - len(t)
while l <= r:
	mid = (l + r) // 2
	var = [0] * len(arr)
	for i in range(mid):
		var[arr[i] - 1] = 1
	f = 0
	for i in range(len(s)):
		if var[i]:
			continue
		if f == len(t):
			break
		if s[i] == t[f]:
			f += 1
	if f == len(t):
		cnt = mid
		l = mid + 1
	else:
		r = mid - 1
print(cnt)


s = list(input())
t = list(input())
arr = list((x - 1 for x in map(int, input().split())))
(n, m) = (len(arr), len(t))

def binary_search():
	(f, e) = (0, n)
	while f <= e:
		mid = f + e >> 1
		vis = [0] * n
		for i in range(mid):
			vis[arr[i]] = 1
		(idx, found) = (0, 0)
		for i in range(n):
			if not vis[i] and s[i] == t[idx]:
				idx += 1
			if idx == m:
				found = 1
				break
		if found:
			f = mid + 1
		else:
			e = mid - 1
	return f - 1
print(binary_search())


def isSubSequence(str1, str2, m, n):
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
t = list(input())
p = input()
a = list(map(int, input().split()))

def check(x):
	count = 0
	y = t.copy()
	for i in range(x):
		y[a[i] - 1] = ''
	b = ''.join(y)
	return isSubSequence(p, b, len(p), len(b))
l = 0
r = len(t)
m = (l + r) // 2
while r - l > 1:
	if check(m):
		l = m
	else:
		r = m
	m = (r + l) // 2
print(m)


t = input()
p = input()
ai = list(map(int, input().split()))
n = len(ai)
ti = [[t[i], 1] for i in range(n)]
for i in range(n):
	ai[i] -= 1
num2 = 1

def check(num):
	global num2
	num2 -= 1
	for i in range(num):
		ti[ai[i]][1] = num2
	num3 = 0
	for i in ti:
		if i[1] == num2:
			continue
		if i[0] == p[num3]:
			num3 += 1
			if num3 == len(p):
				return True
	return False
high = n
low = 0
mid = (high + low) // 2
while high >= low:
	if check(mid):
		low = mid + 1
	else:
		high = mid - 1
	mid = (high + low) // 2
print(mid)


from sys import stdin
t = input().strip()
p = input().strip()

def possible(pos):
	it = 0
	ip = 0
	while it < len(t) and ip < len(p):
		if it in d:
			it += 1
			continue
		if t[it] == p[ip]:
			it += 1
			ip += 1
		else:
			it += 1
	if ip == len(p):
		return True
	else:
		return False
a = [int(x) - 1 for x in stdin.readline().split()]
l = 0
r = len(t) - len(p)
d = set()
while l < r:
	mid = (l + r) // 2
	if len(d) < mid + 1:
		for i in range(len(d), mid + 1):
			d.add(a[i])
	else:
		for i in range(mid + 1, len(d), 1):
			d.discard(a[i])
	if possible(mid):
		l = mid + 1
	else:
		r = mid
print(l)


def canFind(ss, t, arr, mid):
	s = ss.copy()
	for i in range(mid):
		s[arr[i] - 1] = '#'
	k = 0
	for i in range(len(t)):
		flag = False
		for j in range(k, len(s)):
			if t[i] == s[j]:
				flag = True
				k = j + 1
				break
		if not flag:
			return False
	return True
s = list(input())
t = list(input())
arr = list(map(int, input().split()))
n = len(arr)
l = 0
r = n
ans = 0
while l <= r:
	mid = (l + r) // 2
	if canFind(s, t, arr, mid):
		ans = mid
		l = mid + 1
	else:
		r = mid - 1
print(ans)


import sys

def debug(x, table):
	for (name, val) in table.items():
		if x is val:
			print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
			return None

def solve():
	t = input()
	p = input()
	A = [int(i) - 1 for i in input().split()]
	ans = nibutan(t, p, A)
	print(ans)

def nibutan(t, p, A):
	top = len(A)
	btm = 0
	while top - btm > 1:
		mid = (top + btm) // 2
		if ex_subs(t, p, A, mid):
			btm = mid
		else:
			top = mid
	return btm

def ex_subs(t, p, A, mid):
	tc = list(t)
	p = list(p)
	for i in range(mid):
		tc[A[i]] = '#'
	k = 0
	cnt = 0
	for c in p:
		if k == len(tc):
			return False
		for j in range(k, len(tc)):
			k += 1
			if c == tc[j]:
				cnt += 1
				break
	return cnt == len(p)
solve()


def mi():
	return map(int, input().split())
s = list(input())
t = input()
a = list(map(int, input().split()))

def isSubSequence(str1, str2, m, n):
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m
l = len(a)
high = l
low = 0
bestans = -1
while low <= high:
	mid = (low + high) // 2
	b = a.copy()
	s1 = s.copy()
	for i in range(mid):
		s1[b[i] - 1] = ''
	s1 = ''.join(s1)
	if isSubSequence(t, s1, len(t), len(s1)):
		low = mid + 1
		bestans = max(bestans, mid)
	else:
		high = mid - 1
print(bestans)


t = input()
p = input()
a = list(map(int, input().strip().split()))
a = [x - 1 for x in a]
n = len(t)
m = len(p)
lo = 0
hi = n - 1
while lo < hi:
	mid = lo + hi >> 1
	temp = list(t)
	for x in a[:mid + 1]:
		temp[x] = '_'
	(ptr, curr) = (0, 0)
	while ptr < n and curr < m:
		while ptr < n and temp[ptr] != p[curr]:
			ptr += 1
		if ptr < n:
			ptr += 1
			curr += 1
	if curr == m:
		lo = mid + 1
	else:
		hi = mid
print(lo)


def isSubStr(word, liveTimes, str, time):
	p = 0
	for i in range(len(word)):
		if time < liveTimes[i] and word[i] == str[p]:
			p += 1
		if p == len(str):
			break
	return p == len(str)
(p, t, perms) = (input(), input(), input().split())
liveTimes = [0 for _ in range(len(p))]
for i in range(len(perms)):
	liveTimes[int(perms[i]) - 1] = i + 1
(L, R, maxT) = (0, len(p), 0)
while L <= R:
	mid = L + (R - L) // 2
	if isSubStr(p, liveTimes, t, mid):
		maxT = max(mid, maxT)
		L = mid + 1
	else:
		R = mid - 1
print(maxT)


import os
import sys
from io import BytesIO, IOBase
from math import log2, ceil, sqrt, gcd, log
from collections import *
from bisect import *
from heapq import *
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
g = lambda : input().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
rr = lambda x: reversed(range(x))
mod = int(1000000000.0) + 7
inf = float('inf')
(frm, to) = (g(), g())
p = gil()
for i in range(len(p)):
	p[i] -= 1
n = len(frm)
m = len(to)
canUse = [1] * n

def isPos(x):
	for i in range(n):
		canUse[i] = 1
	for j in range(x):
		canUse[p[j]] = 0
	j = 0
	for i in range(n):
		if j < m and canUse[i] and (to[j] == frm[i]):
			j += 1
	return j == m
(l, r) = (1, len(frm))
ans = 0
while l <= r:
	mid = (l + r) // 2
	if isPos(mid):
		ans = mid
		l = mid + 1
	else:
		r = mid - 1
print(ans)


def good(t, p, b, k):
	j = 0
	for i in range(len(t)):
		if b[i] >= k and t[i] == p[j]:
			j += 1
			if j == len(p):
				return True
	return False

def solve(t, p, a):
	b = [0] * len(a)
	for i in range(len(a)):
		b[a[i] - 1] = i
	low = 0
	high = len(a)
	while low + 1 < high:
		mid = (low + high) // 2
		if good(t, p, b, mid):
			low = mid
		else:
			high = mid
	return low
t = input()
p = input()
a = list(map(int, input().split()))
print(solve(t, p, a))


def modinv(n, p):
	return pow(n, p - 2, p)

def is_present(parent, child):
	m = 0
	i = 0
	j = 0
	lc = len(child)
	lp = len(parent)
	while i < len(child) and j < len(parent):
		while i < lc and j < lp and (child[i] == parent[j]):
			i += 1
			j += 1
			m += 1
		while i < lc and j < lp and (parent[j] != child[i]):
			j += 1
	return m == len(child)

def main():
	t = input()
	p = input()
	moves = [int(x) for x in input().split()]
	l = 0
	r = len(moves) - 1
	ans_s = []
	while r > l:
		m = (r + l) // 2
		removed = set(moves[:m + 1])
		new_s = []
		for i in range(len(t)):
			if i + 1 not in removed:
				new_s.append(t[i])
		if is_present(new_s, p):
			ans_s = new_s
			l = m + 1
		else:
			r = m
	if is_present(ans_s, p):
		print(len(t) - len(ans_s))
	else:
		print(0)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import os
import sys
from io import BytesIO, IOBase
from typing import Set

def ok(a: str, b: str, indices: Set[int]) -> bool:
	c = ''.join([a[i] for i in range(len(a)) if i not in indices])
	(i, j) = (len(c) - 1, len(b) - 1)
	while i >= 0 and j >= 0:
		if c[i] == b[j]:
			j -= 1
		i -= 1
	return j == -1

def discrete_binary_search(funct, lo, hi, a, b, indices):

	def func(x: int) -> bool:
		return not ok(a, b, set(indices[:x]))
	while lo < hi:
		mi = lo + (hi - lo) // 2
		if func(mi):
			hi = mi
		else:
			lo = mi + 1
	return lo

def main():
	(s, t) = (input(), input())
	indices = [int(_) - 1 for _ in input().split()]
	print(discrete_binary_search(ok, 0, len(indices), s, t, indices) - 1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys

def bits(n: int):
	return list(bin(n)).count('1')

def main(test_case=False):
	n = int(input()) if test_case else 1
	for _ in range(n):
		test()

def flush():
	sys.stdout.flush()

def parr(arr):
	print(*arr, sep=' ')

def gcd(a, b):
	while b:
		if b % a == 0:
			break
		tmp = a
		a = b % a
		b = tmp
	return a
t = ''
p = ''
a = []
step = 0
mark = []

def ok(s):
	global p
	t = s
	i = 0
	j = 0
	n = len(t)
	m = len(p)
	while i < n:
		if t[i] == p[j]:
			j += 1
		i += 1
		if j == m:
			return True
	return False

def fun(index):
	global step
	global t
	r = ''
	step += 1
	for i in range(index + 1):
		mark[a[i] - 1] = step
	n = len(t)
	for i in range(n):
		if mark[i] == step:
			continue
		else:
			r += t[i]
	return r

def test():
	global t
	global p
	global a
	global mark
	t = input()
	p = input()
	a = list(map(int, input().split()))
	n = len(t)
	mark = [0] * n
	left = 0
	right = n - 1
	ans = 0
	while left <= right:
		mid = (left + right) // 2
		if ok(fun(mid)):
			ans = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	print(ans)
main(False)


def checksub(tmp, t):
	j = 0
	n = len(tmp)
	m = len(t)
	for i in range(n):
		if t[j] == tmp[i]:
			j += 1
		if j == m:
			return True
	return False

def solve(p, t, perms):
	l = 0
	h = len(p) - 1
	ans = 0
	while l <= h:
		m = int((l + h) / 2)
		tmp = list(p)
		for i in range(m):
			tmp[perms[i] - 1] = '_'
		if checksub(tmp, t):
			ans = m
			l = m + 1
		else:
			h = m - 1
	return ans
p = input()
t = input()
lst = list(map(int, input().split()))
print(solve(p, t, lst))


t = list(input())
p = list(input())

def has_sub(temp):
	idx = 0
	for c in temp:
		if c == p[idx]:
			idx += 1
		if idx == len(p):
			return True
	return False
arr = list(map(int, input().split()))
left = 0
right = len(arr) - 1
while left < right:
	mid = (left + right + 1) // 2
	temp = t[:]
	for idx in range(mid):
		temp[arr[idx] - 1] = '0'
	if has_sub(temp):
		left = mid
	else:
		right = mid - 1
print(right)


t = input()
p = input()
a = list(map(int, input().split()))

def can(s, p):
	i = 0
	for ch in s:
		if ch == p[i]:
			i += 1
			if i == len(p):
				return True
	return False

def binary_search(l, r):
	while l < r - 1:
		s = list(t)
		mid = (l + r) // 2
		for index in range(mid):
			s[a[index] - 1] = ' '
		ok = False
		i = 0
		for ch in s:
			if ch == p[i]:
				i += 1
				if i == len(p):
					ok = True
					break
		if ok:
			l = mid
		else:
			r = mid
	return l
print(binary_search(0, len(a) + 1))


def isSubSequence(pat, text, Done):
	t = 0
	for i in range(len(text)):
		if t < len(pat) and text[i] == pat[t] and (i + 1 not in Done):
			t += 1
	return t == len(pat)
s = input()
r = input()
A = list(map(int, input().split()))
n = len(A)
low = 0
high = n
while low < high:
	mid = (low + high) // 2 + 1
	if isSubSequence(r, s, set(A[:mid])):
		low = mid
	else:
		high = mid - 1
print(low)


def check(index, string, string2, arr):
	string1 = list(string)
	for i in range(index + 1):
		string1[arr[i] - 1] = '-1'
	j = 0
	for i in range(len(string1)):
		if string1[i] == string2[j]:
			j += 1
		if j == len(string2):
			return True
	return False

def main():
	string1 = str(input())
	string2 = str(input())
	a = list(map(int, input().split()))
	start = 0
	ans = -1
	end = len(a) - 1
	while start <= end:
		mid = start + (end - start) // 2
		if check(mid, string1, string2, a):
			ans = mid
			start = mid + 1
		else:
			end = mid - 1
	print(ans + 1)
	return
main()


import sys
inp = input()
tar = input()
seq = list(map(int, input().split()))
l_inp = len(inp)
l_tar = len(tar)

def check_for_m(m):
	banned = set(seq[:m])
	ip = 0
	for i in range(l_inp):
		if not i + 1 in banned:
			if inp[i] == tar[ip]:
				ip += 1
			if ip == l_tar:
				return True
	return False
l = 0
r = l_inp + 1
while l + 1 < r:
	m = (l + r) // 2
	if check_for_m(m):
		l = m
	else:
		r = m
print(l)


def check(tt, p):
	(i, j) = (0, 0)
	while i < len(t):
		if tt[i] == p[j]:
			j += 1
		i += 1
		if j == len(p):
			break
	if j == len(p):
		return 1
	else:
		return 0
t = list(input())
p = list(input())
n = len(t)
a = list(map(int, input().split()))
(l, r, ans) = (0, n - 1, 0)
while l <= r:
	m = (l + r) // 2
	tt = t.copy()
	for i in range(m + 1):
		tt[a[i] - 1] = ''
	if check(tt, p):
		l = m + 1
		ans = m + 1
	else:
		r = m - 1
print(ans)


from sys import stdin

def input():
	return stdin.readline()
s = list(input())
t = input()
a = list(map(lambda x: int(x) - 1, input().split()))
n = len(a)

def can(s):
	cur = 0
	for (i, ch) in enumerate(s):
		if ch == t[cur]:
			cur += 1
		if cur == len(t):
			return True
	return False
(left, right) = (-1, n)
while left + 1 < right:
	mid = left + right >> 1
	temp = s[:]
	for i in range(mid):
		temp[a[i]] = ''
	if can(''.join(temp)):
		left = mid
	else:
		right = mid
print(left)


def isValid(t, t1, l, mid):
	temp = []
	for i in range(len(l)):
		temp.append(t[i])
	for i in range(mid):
		temp[l[i] - 1] = ' '
	m = len(t1)
	n = len(temp)
	i = 0
	j = 0
	while j < m and i < n:
		if temp[i] == t1[j]:
			j = j + 1
		i = i + 1
	if j == m:
		return True
	return False
t = list(input())
t1 = list(input())
l = list(map(int, input().split()))
n = len(t)
s = 0
e = n
r = 0
while s <= e:
	mid = s + int((e - s) / 2)
	if isValid(t, t1, l, mid) == True:
		s = mid + 1
		r = mid
	else:
		e = mid - 1
print(r)


import sys
sys.setrecursionlimit(2 ** 20)
DEBUG = 0

def testRemove(string, target, remove, until):
	copy = string.copy()
	for i in remove[:until]:
		copy[i - 1] = 0
	if DEBUG:
		print(copy, string)
	j = 0
	for i in copy:
		if i == target[j]:
			j += 1
	if j == len(target):
		return 1
	return 0

def binSearch(string, target, remove, lo, hi):
	mid = lo + (hi - lo + 1) // 2
	if lo >= hi:
		if testRemove(string, target, remove, mid):
			return mid
		return mid + 1
	if testRemove(string, target, remove, mid):
		return binSearch(string, target, remove, mid, hi)
	return binSearch(string, target, remove, lo, mid - 1)
string = list(input()) + ['\x00']
target = list(input()) + ['\x00']
remove = list(map(int, input().split()))
answer = binSearch(string, target, remove, 0, len(remove) - 1)
print(answer)


(t, p) = (input(), input())
indices = tuple(map(int, input().split()))
n = len(t)
np = len(p)
l = 0
right = n
ans = 0
while n - l > 1:
	m = (l + right) // 2
	if l == m:
		break
	tu = list(t)
	for i in range(l, m):
		tu[indices[i] - 1] = '0'
	pos = 0
	yes = 0
	for i in tu:
		if i == p[pos]:
			pos += 1
		if pos == np:
			yes = 1
			break
	if yes:
		ans += m - l
		t = ''.join(tu)
		l = m
		right = n
	else:
		right = m
print(ans)


import os
import sys
from io import BytesIO, IOBase

def main():
	s = list(input())
	t = list(input())
	perm = list(map(int, input().split(' ')))
	low = 0
	high = len(s)

	def pos(midd):
		temp = list()
		here = set(perm[:midd + 1])
		for x in range(len(s)):
			if x + 1 not in here:
				temp.append(s[x])
		low = 0
		for x in range(len(temp)):
			if temp[x] == t[low]:
				low += 1
			if low == len(t):
				return True
		return False
	while low <= high:
		mid = (low + high) // 2
		if pos(mid):
			low = mid + 1
		else:
			high = mid - 1
	print(low)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


b = input()
s = input()
i = [int(x) - 1 for x in input().split()]

def viable(x):
	ind = 0
	ok = [0] * len(b)
	for j in range(0, x):
		ok[i[j]] = 1
	for j in range(0, len(b)):
		if s[ind] == b[j] and ok[j] != 1:
			ind += 1
			if ind == len(s):
				break
	if ind == len(s):
		return True
	else:
		return False
low = 0
high = len(b)
while low < high:
	mid = (low + high) // 2
	if viable(mid):
		ans = mid
		low = mid + 1
	else:
		high = mid
print(ans)


t = input().strip()
p = input().strip()
A = list(map(int, input().strip().split()))

def fn(c):
	s = set(A[:c])
	st = []
	for i in range(len(t)):
		if (i + 1 in s) == False:
			st.append(t[i])
	p1 = 0
	p2 = 0
	while p1 != len(st) and p2 != len(p):
		if st[p1] == p[p2]:
			p2 += 1
		p1 += 1
	if p2 == len(p):
		return True
	else:
		return False
r = 0
l = len(A)
while l - r > 1:
	c = int((r + l) // 2)
	if fn(c) == True:
		r = c
	else:
		l = c
print(r)


import sys
input = sys.stdin.readline
t = input().rstrip()
p = input().rstrip()
a = list(map(int, input().split()))
l = 0
r = len(a)
while r - l > 1:
	mid = (r + l) // 2
	s = set(a[:mid])
	j = 0
	for i in range(len(t)):
		if j < len(p) and t[i] == p[j] and (i + 1 not in s):
			j += 1
	if j == len(p):
		l = mid
	else:
		r = mid
print(l)


a = input()
b = input()
p = list(map(int, input().split()))
for i in range(len(p)):
	p[i] -= 1

def good(m):
	pos = 0
	a1 = list(a)
	for i in range(m):
		a1[p[i]] = '#'
	for i in range(len(a1)):
		if a1[i] == b[pos]:
			pos += 1
			if pos == len(b):
				return True
	return False
l = 0
r = len(a)
while r - l > 1:
	m = (l + r) // 2
	if good(m):
		l = m
	else:
		r = m
print(l)


s = input()
p = input()
a = [i - 1 for i in list(map(int, input().split()))]
left = 0
right = len(s)
while right - left > 1:
	d = list(s)
	mid = int((left + right) / 2)
	for i in range(mid):
		d[a[i]] = ''
	j = 0
	for i in range(len(s)):
		if p[j] == d[i]:
			j += 1
			if j == len(p):
				left = mid
				break
	if j != len(p):
		right = mid
print(left)


import sys
inp = sys.stdin.readline

def input():
	return inp().strip()

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def main():
	(p, t) = (input(), input())
	a = lin()
	n = len(p)

	def check(x):
		rm = set(a[:x])
		p1 = [p[i] for i in range(n) if i + 1 not in rm]
		dc = {}
		for (i, j) in enumerate(p1):
			try:
				dc[j].append(i)
			except:
				dc[j] = [i]
		for i in dc:
			dc[i] = dc[i][::-1]
		pv = -1
		for i in t:
			if i in dc:
				while dc[i]:
					ch = dc[i].pop()
					if ch > pv:
						pv = ch
						break
				else:
					return False
			else:
				return False
		return True
	ans = 0
	(left, right) = (0, n - 1)
	while left < right:
		md = left + right + 1 >> 1
		if check(md):
			ans = max(md, ans)
			left = md
		else:
			right = md - 1
	print(ans)
main()


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import time
start_time = time.time()
import collections as col
import math, string
from functools import reduce

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def is_Subsequence(s1, s2):
	m = len(s1)
	n = len(s2)
	i = j = 0
	while j < m and i < n:
		if s1[j] == s2[i]:
			j += 1
		i += 1
	return j == m

def solve():
	S = getStr()
	T = getStr()
	A = getInts()
	left = 0
	right = len(S) - len(T) + 1
	prev_middle = 0
	s_tmp = list(S)
	while right - left > 1:
		middle = (left + right) // 2
		if middle < prev_middle:
			for j in range(middle, prev_middle):
				s_tmp[A[j] - 1] = S[A[j] - 1]
		else:
			for j in range(prev_middle, middle):
				s_tmp[A[j] - 1] = ''
		if is_Subsequence(T, s_tmp):
			prev_middle = middle
			left = middle
		else:
			prev_middle = middle
			right = middle
	return left
print(solve())


a = input()
b = input()
arr = list(map(int, input().split()))
start = 0
end = len(arr) - len(b)
la = len(a)
lb = len(b)
while start <= end:
	mid = (start + end) // 2
	temp = [0] * len(arr)
	for i in range(mid):
		temp[arr[i] - 1] = 1
	temp2 = 0
	for i in range(la):
		if temp[i]:
			continue
		if temp2 == lb:
			break
		if a[i] == b[temp2]:
			temp2 += 1
	if temp2 == lb:
		ans = mid
		start = mid + 1
	else:
		end = mid - 1
print(ans)