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.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: String algorithms

Sorting

Greedy algorithms


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()
a = [int(x) - 1 for x in input().split()]

def ok(n):
	bad = set(a[:n])
	it = (a for (i, a) in enumerate(s) if i not in bad)
	return all((c in it for c in t))
low = 0
high = len(s)
while low < high:
	mid = (high + low + 1) // 2
	if ok(mid):
		low = mid
	else:
		high = mid - 1
print(high)


import sys
from array import array

def input():
	return sys.stdin.buffer.readline().decode('utf-8')
s = input().rstrip()
t = input().rstrip()
(n, m) = (len(s), len(t))
p = tuple(map(lambda x: int(x) - 1, input().split()))

def solve(x):
	ok = array('b', [1]) * n
	for i in p[:x]:
		ok[i] = 0
	j = 0
	for i in range(n):
		if ok[i] and s[i] == t[j]:
			j += 1
			if j == m:
				return True
	return False
(ok, ng) = (0, n)
while abs(ok - ng) > 1:
	mid = ok + ng >> 1
	if solve(mid):
		ok = mid
	else:
		ng = mid
print(ok)


import sys
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 8
N = 5 * 10 ** 6

def solve(no):
	se = set(a[:no])
	flag = False
	ite = 0
	for i in range(len(s)):
		if i in se:
			continue
		if s[i] == t[ite]:
			ite += 1
		if ite == len(t):
			flag = True
			break
	return flag
s = ri()
t = ri()
a = Ri()
a = [i - 1 for i in a]
l = 0
h = len(a)
maxx = 0
while l <= h:
	mid = (l + h) // 2
	if solve(mid):
		maxx = max(maxx, mid)
		l = mid + 1
	else:
		h = mid - 1
print(maxx)


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

def exist(m):
	vis = [0] * len(s)
	for i in range(m):
		vis[a[i] - 1] = 1
	j = 0
	for i in range(len(s)):
		if vis[i] == 0:
			if s[i] == t[j]:
				j += 1
			if j == len(t):
				return 1
	return 0
(l, r) = (0, len(s))
while l < r:
	mid = (l + r + 1) // 2
	if exist(mid):
		l = mid
	else:
		r = mid - 1
print(l)


def func(s1, s2):
	n = len(s1)
	m = len(s2)
	k = 0
	for i in range(n):
		if s1[i] == s2[k]:
			k = k + 1
		if k == m:
			return True
			break
	return False
s1 = list(input())
s2 = list(input())
a = list(map(int, input().strip().split(' ')))
high = len(a)
low = 0
b = []
qw = 0
w = -1
for i in s1:
	b.append(i)
while low <= high:
	mid = (low + high) // 2
	if qw == 0:
		for i in range(low, mid + 1):
			s1[a[i] - 1] = '8'
	if func(s1, s2) == True:
		w = mid
		low = mid + 1
		qw = 0
	else:
		high = mid - 1
		mid1 = (high + low) // 2
		for i in range(mid1 + 1, mid + 1):
			s1[a[i] - 1] = b[a[i] - 1]
		qw = 1
if w != -1:
	print(w + 1)
else:
	print(0)


def is_subsequence(a, b, idx, top):
	i = 0
	for (j, c) in enumerate(a):
		if c == b[i] and idx[j + 1] > top:
			i += 1
		if i == len(b):
			return True
	return False
a = input()
b = input()
r = list(map(int, input().split()))
idx = [0 for _ in range(len(r) + 1)]
for i in range(len(r)):
	idx[r[i]] = i
lo = -1
hi = len(a)
while hi - lo > 1:
	mi = (lo + hi) // 2
	if is_subsequence(a, b, idx, mi):
		lo = mi
	else:
		hi = mi
print(lo + 1)


def main():
	a_string = input()
	b_string = input()
	moves = [int(x) for x in input().split()]
	index_of_move = {}
	lenb = len(b_string)
	for (index, elem) in enumerate(moves):
		index_of_move[elem] = index + 1
	l = 0
	r = len(moves) - 1
	while l < r:
		middle = int((l + r + 1) / 2)
		bi = 0
		i = 0
		for (index, elem) in enumerate(a_string):
			if index_of_move[index + 1] <= middle + 1:
				continue
			if elem is b_string[bi]:
				bi += 1
			if bi >= lenb:
				break
		if bi >= lenb:
			l = middle
		else:
			r = middle - 1
	if l is 0 and r is 0:
		bi = 0
		for (index, elem) in enumerate(a_string):
			if index_of_move[index + 1] <= 1:
				continue
			if elem is b_string[bi]:
				bi += 1
			if bi >= lenb:
				break
		if bi >= lenb:
			print(1)
		else:
			print(0)
	else:
		print(l + 1)

def __starting_point():
	main()
__starting_point()


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]

def sub(x):
	have = set(a[:x])
	i = 0
	j = 0
	while i < len(s) and j < len(t):
		if i + 1 not in have and s[i] == t[j]:
			j += 1
		i += 1
	return j == len(t)
s = input()
t = input()
a = array()
low = 0
high = len(a)
while low <= high:
	mid = low + (high - low) // 2
	if sub(mid):
		ans = mid
		low = mid + 1
	else:
		high = mid - 1
print(ans)


def solution(a, b, c):

	def check(x):
		temp = list(a)
		for i in range(x):
			temp[c[i] - 1] = '$'
		j = 0
		for i in range(len(temp)):
			if temp[i] == b[j]:
				j += 1
			if j == len(b):
				return True
		return False
	low = 0
	high = len(a) - 1
	ans = 0
	while low <= high:
		mid = low + (high - low) // 2
		if check(mid) == True:
			low = mid + 1
			ans = mid
		else:
			high = mid - 1
	return ans
a = input()
b = input()
c = [int(x) for x in input().split(' ')]
print(solution(a, b, c))


import sys
from typing import List
input = sys.stdin.readline

def solve(t: str, p: str, a: List[int]) -> int:

	def verify(pivot: int) -> bool:
		pass
		j = 0
		a_set = set(a[:pivot])
		for i in range(lt):
			if t[i] == p[j] and i not in a_set:
				j += 1
				if j == lp:
					return True
		return False
	a = [e - 1 for e in a]
	(lt, lp) = (len(t), len(p))
	(lo, hi) = (0, len(a))
	r = None
	while lo <= hi:
		pivot = (lo + hi) // 2
		if verify(pivot):
			r = pivot
			lo = pivot + 1
		else:
			hi = pivot - 1
	return r
t = input().strip()
p = input().strip()
a = list(map(int, input().strip().split()))
r = solve(t, p, a)
print(r)


import logging
import sys
from operator import add, sub
from asyncio.log import logger
nivel_log = logging.ERROR
logger_cagada = None
from bisect import bisect_left, bisect_right

class SortedCollection(object):

	def __init__(self, iterable=(), key=None):
		self._given_key = key
		key = (lambda x: x) if key is None else key
		decorated = sorted(((key(item), item) for item in iterable))
		self._keys = [k for (k, item) in decorated]
		self._items = [item for (k, item) in decorated]
		self._key = key

	def _getkey(self):
		return self._key

	def _setkey(self, key):
		if key is not self._key:
			self.__init__(self._items, key=key)

	def _delkey(self):
		self._setkey(None)
	key = property(_getkey, _setkey, _delkey, 'key function')

	def clear(self):
		self.__init__([], self._key)

	def copy(self):
		return self.__class__(self, self._key)

	def __len__(self):
		return len(self._items)

	def __getitem__(self, i):
		return self._items[i]

	def __iter__(self):
		return iter(self._items)

	def __reversed__(self):
		return reversed(self._items)

	def __repr__(self):
		return '%s(%r, key=%s)' % (self.__class__.__name__, self._items, getattr(self._given_key, '__name__', repr(self._given_key)))

	def __reduce__(self):
		return (self.__class__, (self._items, self._given_key))

	def __contains__(self, item):
		k = self._key(item)
		i = bisect_left(self._keys, k)
		j = bisect_right(self._keys, k)
		return item in self._items[i:j]

	def index(self, item):
		k = self._key(item)
		i = bisect_left(self._keys, k)
		j = bisect_right(self._keys, k)
		return self._items[i:j].index(item) + i

	def count(self, item):
		k = self._key(item)
		i = bisect_left(self._keys, k)
		j = bisect_right(self._keys, k)
		return self._items[i:j].count(item)

	def insert(self, item):
		k = self._key(item)
		i = bisect_left(self._keys, k)
		self._keys.insert(i, k)
		self._items.insert(i, item)

	def insert_right(self, item):
		k = self._key(item)
		i = bisect_right(self._keys, k)
		self._keys.insert(i, k)
		self._items.insert(i, item)

	def remove(self, item):
		i = self.index(item)
		del self._keys[i]
		del self._items[i]

	def find(self, k):
		i = bisect_left(self._keys, k)
		if i != len(self) and self._keys[i] == k:
			return self._items[i]
		raise ValueError('No item found with key equal to: %r' % (k,))

	def find_le(self, k):
		i = bisect_right(self._keys, k)
		if i:
			return self._items[i - 1]
		raise ValueError('No item found with key at or below: %r' % (k,))

	def find_lt(self, k):
		i = bisect_left(self._keys, k)
		if i:
			return self._items[i - 1]
		raise ValueError('No item found with key below: %r' % (k,))

	def find_ge(self, k):
		i = bisect_left(self._keys, k)
		if i != len(self):
			return self._items[i]
		raise ValueError('No item found with key at or above: %r' % (k,))

	def find_gt(self, k):
		i = bisect_right(self._keys, k)
		if i != len(self):
			return self._items[i]
		raise ValueError('No item found with key above: %r' % (k,))

def cacadena_es_subsequencia(cadenota, cadenita, posiciones_cadenota):
	idx_act = -1
	si = True
	posiciones_subseq = SortedCollection()
	for carajo in cadenita:
		try:
			idx_act = posiciones_cadenota[carajo].find_gt(idx_act)
		except ValueError as e:
			si = False
			break
		posiciones_subseq.insert(idx_act)
	return posiciones_subseq if si else None

def cacadena_remover_posicion(cadenota, posiciones_cadena, posicion):
	letra = cadenota[posicion]
	posiciones_cadena[letra].remove(posicion)
	return letra

def cacadena_genera_posiciones_cadena(cadenota, posiciones_cadena):
	for (posicion, letra) in enumerate(cadenota):
		posiciones_cadena.setdefault(letra, SortedCollection()).insert(posicion)

def cadena_remover_posiciones(cadenota, posiciones_cadena, indices_culeros, respaldo):
	for idx_a_borrar in indices_culeros:
		letra = cacadena_remover_posicion(cadenota, posiciones_cadena, idx_a_borrar)
		respaldo.append((idx_a_borrar, letra))

def cadena_restaurar_posiciones(cadenota, posiciones_cadena, respaldo):
	for (idx_borrado, letra) in respaldo:
		posiciones_cadena[letra].insert(idx_borrado)

def cadena_poner_posiciones(cadenota, posiciones_cadena, indices_culeros, respaldo):
	logger_cagada.debug('los idxs q c ponen {}'.format(indices_culeros))
	for idx_a_poner in indices_culeros:
		letra = cadenota[idx_a_poner]
		respaldo.append((idx_a_poner, letra))
	cadena_restaurar_posiciones(cadenota, posiciones_cadena, respaldo)

def cadena_quitar_caca(cadenota, cadenota_tmp, mierdas):
	for mierda in mierdas:
		cadenota_tmp[mierda] = ','

def cadena_poner_caca(cacadenota, cadenota_tmp, mierdas):
	for mierda in mierdas:
		cadenota_tmp[mierda] = cacadenota[mierda]

def cadena_find_caca(cadenota, cadenita):
	idx_cadenota = 0
	cadenota_tam = len(cadenota)
	encontrados = 0
	for caca in cadenita:
		while idx_cadenota < cadenota_tam and caca != cadenota[idx_cadenota]:
			idx_cadenota += 1
		if idx_cadenota < cadenota_tam:
			encontrados += 1
		idx_cadenota += 1
	logger_cagada.debug('los encontraods {}'.format(encontrados))
	return encontrados == len(cadenita)

def cacadena_core(cadenota, cadenita, indices_culeros):
	posiciones_cadena = {}
	idx_borrados_cnt = 0
	logger_cagada.debug('la cad {} la cadenita {} los idx cul {}'.format(len(cadenota), len(cadenita), len(indices_culeros)))
	operacion = add
	delta = len(cadenota)
	exp_2 = 1
	while exp_2 < delta:
		exp_2 <<= 1
	delta = exp_2
	tam_brinco = 0
	ultimo_bueno = 0
	cadenota_tam = len(cadenota)
	cacadenota_tmp = [x for x in cadenota]
	while True:
		posiciones_subseq = None
		idx_ini = 0
		idx_fin = 0
		operacion_en_posiciones_letra = None
		tam_brinco = operacion(tam_brinco, delta)
		logger_cagada.debug('el brinco es {} l delta {}'.format(tam_brinco, delta))
		if operacion == add:
			idx_ini = tam_brinco - delta
			idx_fin = tam_brinco
			operacion_en_posiciones_letra = cadena_quitar_caca
		else:
			idx_ini = tam_brinco
			idx_fin = tam_brinco + delta
			operacion_en_posiciones_letra = cadena_poner_caca
		logger_cagada.debug('el idx ini {} idx fin {}'.format(idx_ini, idx_fin))
		operacion_en_posiciones_letra(cadenota, cacadenota_tmp, indices_culeros[idx_ini:idx_fin])
		posiciones_subseq = cadena_find_caca(cacadenota_tmp, cadenita)
		logger_cagada.debug('se ncontro mierda {}'.format(posiciones_subseq))
		if posiciones_subseq:
			if delta == len(cadenota) or delta == 1:
				break
			operacion = add
			ultimo_bueno = tam_brinco
		else:
			if delta == 1:
				tam_brinco = 0
				break
			operacion = sub
		delta >>= 1
	return tam_brinco if tam_brinco else ultimo_bueno

def cacadena_main():
	lineas = list(sys.stdin)
	cadenota = lineas[0].strip()
	cadenita = lineas[1].strip()
	cacas = [int(x) - 1 for x in lineas[2].strip().split(' ')]
	mierda = cacadena_core(cadenota, cadenita, cacas)
	print('{}'.format(mierda))
FORMAT = '[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s'
logging.basicConfig(level=nivel_log, format=FORMAT)
logger_cagada = logging.getLogger('asa')
logger_cagada.setLevel(nivel_log)
cacadena_main()


a = input()
b = input()
c = [int(i) - 1 for i in input().split()]
l = 0
r = len(a)
while r - l > 1:
	m = l + (r - l) // 2
	d = list(a)
	j = 0
	for i in range(m):
		d[c[i]] = ''
	for i in range(len(a)):
		if d[i] == b[j]:
			j += 1
			if j == len(b):
				l = m
				break
	if j != len(b):
		r = m
print(l)


def main():
	(s, w) = (['', *input()], input())
	l = list(map(int, input().split()))
	(lo, hi) = (0, len(s) - len(w))
	while lo < hi:
		(mid, t) = ((lo + hi) // 2, s[:])
		for i in l[:mid]:
			t[i] = ''
		try:
			i = 1
			for c in w:
				while c != t[i]:
					i += 1
				i += 1
		except IndexError:
			hi = mid
		else:
			lo = mid + 1
	print(lo - 1)
main()


t = input()
p = input()
a = [int(v) for v in input().split()]
lt = len(t)
lp = len(p)

def isValid(pos):
	flags = [0] * lt
	for i in range(pos + 1):
		flags[a[i] - 1] = 1
	count = 0
	for i in range(lt):
		if flags[i] == 0 and t[i] == p[count]:
			count += 1
			if count == lp:
				return True
	return False
left = 0
right = lt - 1
ans = -1
while left <= right:
	mid = (left + right) // 2
	if isValid(mid):
		ans = mid
		left = mid + 1
	else:
		right = mid - 1
print(ans + 1)


def can(m):
	u = sorted(a[:m])
	inp = 0
	inu = 0
	for i in range(len(t)):
		if inu < len(u) and i == u[inu] - 1:
			inu += 1
		elif t[i] == p[inp]:
			inp += 1
			if inp == len(p):
				return True
	return False
t = input()
p = input()
a = list(map(int, input().split()))
l = 0
r = len(t)
while r - l > 1:
	m = (r + l) // 2
	if can(m):
		l = m
	else:
		r = m
print(l)


(s, t) = (input(), input())
ind = list(map(int, input().split()))

def is_substring(text, word, exclude):
	wi = 0
	for i in range(len(text)):
		if wi < len(word) and text[i] == word[wi] and (i + 1 not in exclude):
			wi += 1
	return wi == len(word)
(l, r) = (0, len(ind))
while l < r:
	mid = (l + r) // 2 + 1
	if is_substring(s, t, set(ind[:mid])):
		l = mid
	else:
		r = mid - 1
print(l)


P = list(input())
T = list(input())
a = list(map(int, input().split()))

def check(k, p, t, a):
	p1 = p.copy()
	for i in range(k):
		p1[a[i] - 1] = '#'
	(n, m) = (len(p1), len(t))
	(i, j) = (0, 0)
	while i < n and j < m:
		if p1[i] == t[j]:
			i += 1
			j += 1
		else:
			i += 1
	return j == m
(l, r) = (0, len(a))
while r - l > 1:
	mid = (l + r) // 2
	if check(mid, P, T, a):
		l = mid
	else:
		r = mid
print(l)


def findPossible(str1, str2):
	str1length = len(str1)
	str2length = len(str2)
	str1Flag = 0
	str2Flag = 0
	for x in range(0, str1length):
		if str1[x] == str2[str2Flag]:
			str2Flag += 1
		if str2Flag == str2length:
			return True
	return False

def delChr(oldStr, permutation, flag):
	newStr = list(oldStr)
	subPer = permutation[0:flag]
	subPer.sort(reverse=True)
	for x in range(0, flag):
		newStr.pop(subPer[x] - 1)
	return newStr

def check_middle(m, permutation, input, target):
	banned_set = set(permutation[:m])
	target_len = len(target)
	target_pointer = 0
	input_len = len(input)
	for x in range(input_len):
		if not x + 1 in banned_set:
			if input[x] == target[target_pointer]:
				target_pointer += 1
			if target_pointer == target_len:
				return True
	return False
s1 = list(input())
s2 = list(input())
permutation = list(map(int, input().split()))
flag = 0
newStr = s1
left = 0
right = len(s1)
while left + 1 < right:
	m = (left + right) // 2
	if check_middle(m, permutation, s1, s2):
		left = m
		pass
	else:
		right = m
print(left)


def check(i):
	k = 0
	for (c, n) in zip(s, ns):
		if n <= i:
			continue
		if s2[k] == c:
			k += 1
			if k == len(s2):
				return True
	return False
s = input()
s2 = input()
ns = [(i + 1, int(x)) for (i, x) in enumerate(input().split())]
ns.sort(key=lambda x: x[1])
ns = [x[0] for x in ns]
l = 0
r = len(s) + 1
while r - l > 1:
	i = (r + l) // 2
	if check(i):
		l = i
	else:
		r = i
print(l)


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)


from sys import stdin, stdout

def ri():
	return map(int, input().split())

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
t = list(input())
p = input()
a = list(ri())
tt = t[:]
tt[a[0] - 1] = ''
if not subset(''.join(tt), p):
	print(0)
	exit()
s = 0
e = len(a) - 1
while True:
	m = s + (e - s) // 2
	ii = [0] * len(t)
	tt = t[:]
	for i in range(m + 1):
		tt[a[i] - 1] = ''
	if subset(''.join(tt), p):
		s = m
	else:
		e = m
	if e - s == 1:
		print(s + 1)
		exit()


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

def ok(n):
	bad = set()
	for i in range(n):
		bad.add(a[i] - 1)
	pt = 0
	ps = 0
	while pt < len(t) and ps < len(s):
		if ps in bad:
			ps += 1
		elif t[pt] == s[ps]:
			ps += 1
			pt += 1
		else:
			ps += 1
	return pt == len(t)
low = 0
high = len(s)
while high >= low:
	mid = (high + low) // 2
	if ok(mid):
		poss = mid
		low = mid + 1
	else:
		high = mid - 1
print(poss)


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

def good(b):
	i = 0
	l = len(b)
	for c in p:
		while i < l and b[i] != c:
			i += 1
		if i == l:
			return False
		i += 1
	return True

def check(x):
	tt = list(t)
	for p in a[:x]:
		tt[p - 1] = ''
	return good(tt)
(le, ri) = (0, len(t) - 1)
while ri > le:
	me = (le + ri + 1) // 2
	if check(me):
		le = me
	else:
		ri = me - 1
print(le)


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

def check(s1, s2, g):
	m1 = len(s1)
	m2 = len(s2)
	j = 0
	i = 0
	while j < m1 and i < m2:
		if s1[j] == s2[i] and h[i] > g:
			j = j + 1
		i = i + 1
	return j == m1
l = -1
r = n - 1
while l < r:
	md = (l + r + 1) // 2
	if check(b, a, h[p[md]]):
		l = md
	else:
		r = md - 1
print(l + 1)


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())


from collections import defaultdict

def isSubsequence(S, T, List, pos, Pos):
	lenS = len(S)
	lenT = len(T)
	Sx = 0
	Tx = 0
	while Tx < lenT and Sx < lenS:
		if Pos[Sx] <= pos:
			Sx += 1
		elif S[Sx] == T[Tx]:
			Sx += 1
			Tx += 1
		else:
			Sx += 1
	if Tx == lenT:
		return True
	return False
S = input()
T = input()
List = [int(x) for x in input().split()]
N = len(List)
Pos = defaultdict(int)
for i in range(N):
	Pos[List[i] - 1] = i
N = len(List)
l = 0
r = N - 1
while l < r:
	mid = l + r >> 1
	if isSubsequence(S, T, List, mid, Pos):
		l = mid + 1
	else:
		r = mid
print(l)


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)


def binary_search(lis, l, r, txt, txt2):
	if r >= l:
		mid = l + (r - l) // 2
		templis = lis[0:mid + 1]
		if is_sub(txt, txt2, templis):
			return binary_search(lis, mid + 1, r, txt1, txt2)
		else:
			return binary_search(lis, l, mid - 1, txt1, txt2)
	else:
		return l - 1

def remove(txt, index):
	index = index - 1
	try:
		return txt[0:index] + txt[index + 1:]
	except IndexError:
		return txt[0:index]

def is_sub(txt, txts, limit):
	s = set(limit)
	cur = 0
	for i in range(len(txt)):
		if txt[i] == txts[cur] and i + 1 not in s:
			cur += 1
			if cur == len(txts):
				return True
	return False
txt1 = input()
txt2 = input()
lis = [int(x) for x in input().split()]
print(binary_search(lis, 0, len(lis) - 1, txt1, txt2) + 1)


t = input()
p = input()
block = [int(i) - 1 for i in input().split()]
ind = {}
for i in range(len(block)):
	ind[block[i]] = i

def is_part_and_parcel(s1, s2, mid):
	n = len(s2)
	m = len(s1)
	i = 0
	c = 0
	j = 0
	while i < n and j < m:
		if ind[j] < mid:
			j += 1
			continue
		if s2[i] == s1[j]:
			i += 1
			j += 1
			c += 1
		else:
			j += 1
	return c == n
n = len(t)
m = len(p)
lo = 0
hi = len(block) - 1
while lo <= hi:
	mi = lo + hi >> 1
	if is_part_and_parcel(t, p, mi):
		ans = mi
		lo = mi + 1
	else:
		hi = mi - 1
print(ans)


def check(x):
	temp = []
	for i in t:
		temp.append(i)
	for i in range(x):
		temp[a[i] - 1] = ''
	l = 0
	r = 0
	c = 0
	while r < len(s) and l < len(t):
		if s[r] == temp[l]:
			r += 1
			c += 1
		l += 1
	return c == len(s)
t = input()
s = input()
a = list(map(int, input().split()))
lo = 0
hi = len(a)
while lo < hi - 1:
	mid = lo + (hi - lo) // 2
	if check(mid):
		lo = mid
	else:
		hi = mid
print(lo)


sed = 257
mod = int(1000000000.0 + 7)

def judge(t, p):
	j = 0
	for ch in p:
		while j < len(t) and t[j] != ch:
			j += 1
		if j >= len(t):
			return False
		j += 1
	return True

def generate(t, a, n):
	res = list(t)
	for i in range(n):
		res[a[i] - 1] = '#'
	res = ''.join(res)
	return res.replace('#', '')
t = input()
p = input()
a = list(map(int, input().split()))
(l, r) = (0, len(t) - len(p) + 1)
while l < r - 1:
	m = (l + r) // 2
	tmp = generate(t, a, m)
	if judge(tmp, p):
		l = m
	else:
		r = m
print(l)


def possible(t, p, a, n):
	s = ''
	check = [True] * len(t)
	for i in range(n):
		check[a[i]] = False
	for i in range(len(check)):
		if check[i]:
			s += t[i]
	m = len(s)
	lp = len(p)
	c = 0
	for i in range(m):
		if s[i] == p[c]:
			c += 1
		if c == lp:
			return True
	return False
t = input()
p = input()
a = list(map(int, input().split()))
for i in range(len(a)):
	a[i] -= 1
low = 0
high = len(a)
ans = 0
while low <= high:
	mid = (low + high) // 2
	if possible(t, p, a, mid):
		ans = mid
		low = mid + 1
	else:
		high = mid - 1
print(ans)


def subseq(s, b):
	h = iter(b)
	return all((any((l == ch for l in h)) for ch in s))
t = input()
p = input()
num = [int(x) for x in input().split()]
st = []
l = 0
r = len(num)
ans = r + 1
while l <= r:
	mid = (l + r) // 2
	st = list(t)
	c = num[:mid]
	for i in c:
		st[i - 1] = ''
	if subseq(p, ''.join(st)):
		ans = mid
		l = mid + 1
	else:
		r = mid - 1
print(ans)


def is_obtained(p, t, K):
	i = 0
	for ch in p:
		i = t.find(ch, i) + 1
		if i == 0:
			return False
		while i in K:
			i = t.find(ch, i) + 1
			if i == 0:
				return False
	return True
I = input
(t, p, A) = (I(), I(), list(map(int, I().split())))
(L, R) = (0, len(A) - 1)
while L < R:
	x = (L + R + 1) // 2
	if is_obtained(p, t, set(A[:x])):
		L = x
	else:
		R = x - 1
print(L)


t = input()
p = input()
a = list(map(int, input().split()))
n = len(a)
low = 0
high = n - 1
last = 0
while low <= high:
	mid = (high + low) // 2
	i = 0
	j = 0
	usable = [False] * n
	for ai in a[mid:]:
		usable[ai - 1] = True
	while i < n and j < len(p):
		if usable[i] and t[i] == p[j]:
			i += 1
			j += 1
		else:
			i += 1
	if j == len(p):
		low = mid + 1
		last = mid
	else:
		high = mid - 1
	if mid == (high + low) // 2:
		break
print(last)


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, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().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')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
INF = 999999999999999999999999
alphabets = 'abcdefghijklmnopqrstuvwxyz'

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class SegTree:

	def __init__(self, n):
		self.N = 1 << n.bit_length()
		self.tree = [0] * (self.N << 1)

	def update(self, i, j, v):
		i += self.N
		j += self.N
		while i <= j:
			if i % 2 == 1:
				self.tree[i] += v
			if j % 2 == 0:
				self.tree[j] += v
			(i, j) = (i + 1 >> 1, j - 1 >> 1)

	def query(self, i):
		v = 0
		i += self.N
		while i > 0:
			v += self.tree[i]
			i >>= 1
		return v

def SieveOfEratosthenes(limit):
	isPrime = [True] * (limit + 1)
	isPrime[0] = isPrime[1] = False
	primes = []
	for i in range(2, limit + 1):
		if not isPrime[i]:
			continue
		primes += [i]
		for j in range(i * i, limit + 1, i):
			isPrime[j] = False
	return primes

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		t = list(rs())
		p = list(rs())
		pos = ria()

		def issubseq(temp):
			j = 0
			for i in range(len(temp)):
				if temp[i] == p[j]:
					j += 1
					if j == len(p):
						return True
			return False
		ans = 0
		l = 1
		h = len(t)
		while l <= h:
			mid = (l + h) // 2
			tempt = t.copy()
			for i in range(mid):
				tempt[pos[i] - 1] = '.'
			if issubseq(tempt):
				ans = mid
				l = mid + 1
			else:
				h = mid - 1
		wi(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


t = input()
p = input()
a = list(map(int, input().split()))
for i in range(len(a)):
	a[i] -= 1
step = 0
mark = [0] * len(t)

def check(index):
	global step
	step += 1
	for j in range(index + 1):
		mark[a[j]] = step
	temp_index = 0
	for j in range(len(t)):
		if mark[j] == step:
			continue
		if t[j] == p[temp_index]:
			temp_index += 1
			if temp_index == len(p):
				return True
	return False
left = 0
right = len(a) - 1
while left <= right:
	mid = (left + right + 1) // 2
	if check(mid):
		left = mid + 1
	else:
		right = mid - 1
while check(mid):
	mid += 1
while not check(mid):
	mid -= 1
print(mid + 1)


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)


s = list(input().strip())
t = input().strip()
sq = [int(a) for a in input().strip().split()]
l = len(s)
lt = len(t)

def check(x):
	tmp = s.copy()
	for i in range(x):
		tmp[sq[i] - 1] = '_'
	idx = 0
	for i in range(l):
		if tmp[i] == t[idx]:
			idx += 1
			if idx == lt:
				return True
	return False
low = 0
high = l
while low <= high:
	mid = low + high >> 1
	if check(mid):
		low = mid + 1
	else:
		high = mid - 1
print(high)


def binaryFind():
	c = [0] * lenp
	maxlen = 0
	for i in range(0, mid):
		c[a[i] - 1] = 1
	for i in range(0, lenp):
		if c[i] == 0:
			if p[i] == t[maxlen]:
				maxlen += 1
		if maxlen == lent:
			return True
	return False
p = input()
t = input()
a = list(map(int, input().split()))
lenp = len(p)
lent = len(t)
l = 0
r = lenp
while l <= r:
	mid = (l + r) // 2
	isok = binaryFind()
	if isok == True:
		l = mid + 1
	else:
		r = mid - 1
print(l - 1)


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()


def main():
	t = input()
	p = input()
	n = len(t)
	pos = list(map(lambda x: int(x) - 1, input().split()))

	def f(ind):
		was = [0 for _ in range(n)]
		for i in range(ind + 1):
			was[pos[i]] = 1
		pattern_pos = 0
		for (i, ch) in enumerate(t):
			if was[i] == 0 and pattern_pos < len(p) and (ch == p[pattern_pos]):
				pattern_pos += 1
		return pattern_pos == len(p)
	(l, r) = (0, n)
	while l < r - 1:
		mid = (l + r) // 2
		if f(mid):
			l = mid
		else:
			r = mid
	while l >= 0 and (not f(l)):
		l -= 1
	while l + 1 < n and f(l + 1):
		l += 1
	print(l + 1)
main()


import math as mt
import sys, string
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())

def isSubseq(s, b, v):
	i = 0
	j = 0
	while i < len(s) and j < len(b):
		if s[i] == b[j] and v[i] == 1:
			j += 1
			i += 1
		else:
			i += 1
	if j == len(b):
		return True
	else:
		return False
a = input().strip()
b = input().strip()
s = L()
l = 0
ans = 0
h = len(a)
while l <= h:
	t = mt.ceil((l + h) / 2)
	v = [1 for j in range(len(a))]
	for i in range(t):
		v[s[i] - 1] = 0
	if isSubseq(a, b, v):
		ans = t
		l = t + 1
	else:
		h = t - 1
print(ans)


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)


s = input()
t = input()
arr = [x - 1 for x in map(int, input().split())]
l = 0
r = len(s) - 1

def check(sa, sb):
	j = 0
	for i in range(len(sb)):
		while j < len(sa) and sa[j] != sb[i]:
			j += 1
		if j == len(sa):
			return False
		j += 1
	return True
while l < r:
	mid = l + r + 1 >> 1
	d = list(s)
	for i in range(mid):
		d[arr[i]] = ''
	if check(''.join(d), t):
		l = mid
	else:
		r = mid - 1
print(l)


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 = list(input())
p = list(input())
lis = list(map(int, input().split()))
pp = len(p)
tt = len(t)
l = 0
r = tt
while l <= r:
	mid = l + (r - l) // 2
	tep = t[:]
	for i in range(mid):
		tep[lis[i] - 1] = '#'
	j = i = 0
	while i < tt and j < pp:
		if tep[i] == p[j]:
			j += 1
		i += 1
	if j < pp:
		r = mid - 1
	else:
		l = mid + 1
print(r)


(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)


s = list(input())
p = list(input())
a = list(map(int, input().strip().split(' ')))
n = len(s)
t = len(p)
l = 0
u = n

def possible(x):
	global n, t
	memeory = [True] * n
	for i in range(0, x):
		memeory[a[i] - 1] = False
	j = 0
	for i in range(n):
		if memeory[i] and j < t and (s[i] == p[j]):
			j += 1
	if j == t:
		return True
	else:
		return False
ans = u + 1
while l <= u:
	mid = (u + l) // 2
	if possible(mid):
		l = mid + 1
		ans = mid
	else:
		u = mid - 1
print(ans)


def sub(a, s):
	pa = 0
	ps = 0
	while pa < len(a) and ps < len(s):
		if a[pa] == s[ps]:
			ps += 1
			pa += 1
		else:
			pa += 1
	return ps == len(s)

def subword(t, ord_ar, n):
	t_copy = []
	for i in range(len(ord_ar)):
		if ord_ar[i] >= n:
			t_copy.append(t[i])
	return t_copy

def check(t, p, ord_ar, n):
	s = subword(t, ord_ar, n)
	return sub(s, p)

def bin_s(l, r, f):
	while r > l + 1:
		m = (r + l) // 2
		if f(m):
			l = m
		else:
			r = m
	return l

def main():
	t = input().strip()
	p = input().strip()
	ord_ar = [0] * len(t)
	seq = list(map(int, input().strip().split()))
	for (i, x) in enumerate(seq):
		ord_ar[x - 1] = i
	ans = bin_s(0, len(t), lambda n: check(t, p, ord_ar, n))
	print(ans)
main()


def is_match(string_long, string_short):
	idx_long = 0
	for (idx, value) in enumerate(string_short):
		while idx_long < len(string_long) and string_long[idx_long] != value:
			idx_long += 1
		if idx_long == len(string_long):
			return False
		idx_long += 1
	return idx_long <= len(string_long)

def solve(string_before_delete, string_after_delete, deletes):
	deletes_at_step = list(range(len(deletes)))
	for (idx, value) in enumerate(deletes):
		deletes_at_step[value - 1] = idx + 1
	left = 0
	right = len(deletes)
	while left + 1 < right:
		mid = (left + right + 1) // 2
		string_mid = ''.join([value for (idx, value) in enumerate(string_before_delete) if deletes_at_step[idx] > mid])
		if is_match(string_mid, string_after_delete):
			left = mid
		else:
			right = mid
	return left
string_before_delete = input().strip()
string_after_delete = input().strip()
deletes = list(map(int, input().strip().split(' ')))
print(solve(string_before_delete, string_after_delete, deletes))


def pred(s1, s2, arr, mid):
	n = len(s1)
	m = len(s2)
	marked = [0 for x in range(n)]
	for i in range(mid + 1):
		marked[arr[i] - 1] = 1
	i = 0
	j = 0
	while i < n and j < m:
		if not marked[i] and s1[i] == s2[j]:
			j += 1
		i += 1
	return j != m
s1 = input()
s2 = input()
arr = [int(x) for x in input().split(' ')]
n = len(arr)
l = 0
r = n - 1
while l < r:
	mid = l + (r - l) // 2
	if pred(s1, s2, arr, mid):
		r = mid
	else:
		l = mid + 1
print(l)


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)