You are given two strings $s$ and $t$. The string $s$ consists of lowercase Latin letters and at most one wildcard character '*', the string $t$ consists only of lowercase Latin letters. The length of the string $s$ equals $n$, the length of the string $t$ equals $m$.

The wildcard character '*' in the string $s$ (if any) can be replaced with an arbitrary sequence (possibly empty) of lowercase Latin letters. No other character of $s$ can be replaced with anything. If it is possible to replace a wildcard character '*' in $s$ to obtain a string $t$, then the string $t$ matches the pattern $s$.

For example, if $s=$"aba*aba" then the following strings match it "abaaba", "abacaba" and "abazzzaba", but the following strings do not match: "ababa", "abcaaba", "codeforces", "aba1aba", "aba?aba".

If the given string $t$ matches the given string $s$, print "YES", otherwise print "NO".


-----Input-----

The first line contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) — the length of the string $s$ and the length of the string $t$, respectively.

The second line contains string $s$ of length $n$, which consists of lowercase Latin letters and at most one wildcard character '*'.

The third line contains string $t$ of length $m$, which consists only of lowercase Latin letters.


-----Output-----

Print "YES" (without quotes), if you can obtain the string $t$ from the string $s$. Otherwise print "NO" (without quotes).


-----Examples-----
Input
6 10
code*s
codeforces

Output
YES

Input
6 5
vk*cup
vkcup

Output
YES

Input
1 1
v
k

Output
NO

Input
9 6
gfgf*gfgf
gfgfgf

Output
NO



-----Note-----

In the first example a wildcard character '*' can be replaced with a string "force". So the string $s$ after this replacement is "codeforces" and the answer is "YES".

In the second example a wildcard character '*' can be replaced with an empty string. So the string $s$ after this replacement is "vkcup" and the answer is "YES".

There is no wildcard character '*' in the third example and the strings "v" and "k" are different so the answer is "NO".

In the fourth example there is no such replacement of a wildcard character '*' that you can obtain the string $t$ so the answer is "NO".

Difficulty: EASY
Tags: String algorithms

Implementation

Complete search
Skill types: Complete search
Expected Time Complexity: O(N)

Starter code:

Solutions:
_ = input()
s = input()
t = input()
ans = None
star_ind = s.find('*')
if star_ind == -1:
	if s == t:
		ans = True
	else:
		ans = False
else:
	pref_len = star_ind
	suff_len = len(s) - star_ind - 1
	ans = True
	ans &= pref_len + suff_len <= len(t)
	if pref_len and s[:pref_len]:
		ans &= s[:pref_len] == t[:pref_len]
	if suff_len and t[-suff_len:]:
		ans &= s[-suff_len:] == t[-suff_len:]
print('YES' if ans else 'NO')


(n, k) = map(int, input().split())
s = input().split('*')
t = input()
if len(s) == 1:
	print('YES' if s[0] == t else 'NO')
else:
	print('YES' if t[:len(s[0])] == s[0] and (t[-len(s[1]):] == s[1] if s[1] != '' else True) and (n <= k + 1) else 'NO')


input()
a = input()
b = input()
if '*' in a:
	(x, y) = a.split('*')
	if b.startswith(x) and b.endswith(y) and (len(b) >= len(x) + len(y)):
		print('YES')
	else:
		print('NO')
else:
	print('YES' if a == b else 'NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if m < n - 1:
	print('NO')
elif s == '*':
	print('YES')
elif s.find('*') == -1:
	if s != t:
		print('NO')
	else:
		print('YES')
else:
	(st, dr) = s.split('*')
	tc = t
	t = t.replace(st, '', 1)
	t = t[len(t)::-1]
	dr = dr[len(dr)::-1]
	t = t.replace(dr, '', 1)
	t = t[len(t)::-1]
	if s.replace('*', t) == tc:
		print('YES')
	else:
		print('NO')


(N, M) = input().strip().split()
(s, t) = (input(), input())
if '*' in s:
	(a, b) = s.split('*')
	if t.startswith(a) and t.endswith(b) and (len(a) + len(b) <= len(t)):
		print('YES')
	else:
		print('NO')
else:
	print('YES' if s == t else 'NO')


gi = lambda : list(map(int, input().split()))
(n, m) = gi()
(s, t) = (input(), input())
v = [0] * m
if '*' in s:
	if m < n - 1:
		print('NO')
		exit()
	for k in range(s.index('*')):
		if s[k] != t[k]:
			print('NO')
			exit()
	for k in range(-1, -n, -1):
		if s[k] == '*':
			break
		if s[k] != t[k]:
			print('NO')
			exit()
	print('YES')
elif s == t:
	print('YES')
else:
	print('NO')


_ = input()
s = input()
t = input()
ss = s.split('*')
if len(ss) == 1:
	print('YES' if s == t else 'NO')
else:
	(sb, se) = ss
	if len(sb) + len(se) <= len(t) and t.startswith(sb) and t.endswith(se):
		print('YES')
	else:
		print('NO')


def solve(s, t):
	if len(s) > len(t) + 1:
		return False
	pos = s.find('*')
	if pos == -1:
		return s == t
	left = s[:pos] if pos > 0 else ''
	right = s[pos + 1:]
	if len(left) + len(right) > len(t):
		return False
	return t.startswith(left) and t.endswith(right)

def main():
	(n, m) = map(int, input().strip().split())
	s = input().strip()
	t = input().strip()
	result = solve(s, t)
	print('YES' if result else 'NO')
main()


def solve(a, b, n, m):
	if n - 1 > m:
		print('NO')
	else:
		if '*' in a:
			idx = a.index('*')
		else:
			idx = -1
		if idx == -1:
			print('YES') if a == b else print('NO')
		else:
			y = len(b) - len(a[idx + 1:])
			if len(a) - 1 <= len(b) and a[:idx] == b[:idx] and (a[idx + 1:] == b[y:]):
				print('YES')
			else:
				print('NO')
(n, m) = map(int, input().split())
a = input()
b = input()
solve(a, b, n, m)


(n, m) = map(int, input().split())
s = input()
t = input()
index = s.find('*')
pos = 'YES'
if index < 0:
	if s != t:
		pos = 'NO'
if index == len(s) - 1:
	if len(t) < len(s) - 1:
		pos = 'NO'
	if s[:index] != t[:index]:
		pos = 'NO'
	remainder = t[index:]
	for i in remainder:
		if ord(i) < ord('a') or ord(i) > ord('z'):
			pos = 'NO'
elif index >= 0:
	if len(t) < len(s) - 1:
		pos = 'NO'
	if s[:index] != t[:index]:
		pos = 'NO'
	if s[index + 1:] != t[-len(s[index + 1:]):]:
		pos = 'NO'
	remainder = t[index:index + 1 - len(s)]
	for i in remainder:
		if ord(i) < ord('a') or ord(i) > ord('z'):
			pos = 'NO'
print(pos)


(n, m) = map(int, input().split())
s = input()
t = input()
if s.find('*') == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
elif len(s) - 1 > len(t):
	print('NO')
else:
	k = s.find('*')
	f = 1
	for i in range(k):
		if s[i] != t[i]:
			f = 0
	ps = len(s) - 1
	pt = len(t) - 1
	i = 0
	while i != len(s) - k - 1:
		if s[ps - i] != t[pt - i]:
			f = 0
		i += 1
	if f:
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if '*' not in s:
	if s == t:
		print('YES')
		exit()
	else:
		print('NO')
		exit()
s = s.split('*')
if s[0] == '':
	if t[m - n + 1:] == s[1]:
		print('YES')
		exit()
	else:
		print('NO')
		exit()
if n == 1 and s == '*':
	print('YES')
	exit()
if m < n:
	if t == s[0] + s[1]:
		print('YES')
		exit()
	else:
		print('NO')
		exit()
if s[0] == t[:len(s[0])]:
	t = t[len(s[0]):]
else:
	print('NO')
	exit()
if t.find(s[1]) != -1:
	if t[t.find(s[1]):] == s[1]:
		print('YES')
		exit()
	elif s[1] == '':
		print('YES')
		exit()
	else:
		print('NO')
		exit()
else:
	print('NO')


input()
s1 = input()
s2 = input()
if '*' not in s1:
	if s1 == s2:
		print('YES')
	else:
		print('NO')
	exit(0)
(s11, s12) = s1.split('*')
if len(s2) >= len(s11) + len(s12) and (len(s11) == 0 or s11 == s2[:len(s11)]) and (len(s12) == 0 or s12 == s2[-len(s12):]):
	print('YES')
else:
	print('NO')


(a, b) = map(int, input().split())
c = input()
d = input()
if '*' not in c:
	if c == d:
		print('YES')
	else:
		print('NO')
else:
	z = c.index('*')
	r = len(c) - z - 1
	if c[:z] != d[:z] or c[z + 1:] != d[len(d) - r:] or z + r > len(d):
		print('NO')
	else:
		print('YES')


import sys
(N, M) = map(int, input().split())
org = input()
if org.find('*') == -1:
	target = input()
	if org == target:
		print('YES')
	else:
		print('NO')
	sys.exit(0)
(fir, sec) = org.split('*')
target = input()
firl = target.find(fir)
firr = firl + len(fir) - 1
sec = sec[::-1]
target = target[::-1]
secl = M - target.find(sec) - 1
secr = secl - len(sec) + 1
(secl, secr) = (secr, secl)
if firl == 0 and secr == M - 1 and (firr < secl):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if m < n - 1:
	print('NO')
elif s.count('*') == 0:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	i = 0
	j = 0
	boo = True
	while s[i] != '*' or s[n - j - 1] != '*':
		if s[i] == '*':
			if s[n - j - 1] != t[m - j - 1]:
				boo = False
				break
			else:
				j += 1
		elif s[n - j - 1] == '*':
			if s[i] != t[i]:
				boo = False
				break
			else:
				i += 1
		elif s[i] != t[i] or s[n - j - 1] != t[m - j - 1]:
			boo = False
			break
		else:
			i += 1
			j += 1
	if boo:
		print('YES')
	else:
		print('NO')


(a, b) = input().split()
n = int(a)
m = int(b)
s1 = input()
s2 = input()
if n == 1 and s1[0] == '*':
	print('YES')
elif '*' in s1:
	c = s1.index('*')
	if c == n - 1 and s1[:c] == s2[:c]:
		print('YES')
	elif n - 1 <= m and s1[:c] == s2[:c] and (s1[c + 1:] == s2[-(n - c - 1):]):
		print('YES')
	else:
		print('NO')
elif s1 == s2:
	print('YES')
else:
	print('NO')


def obtainString(lenS, lenT, stringS, stringT):
	wildcardExists = False
	if stringS == stringT:
		return True
	if lenS - lenT >= 2:
		return False
	if stringT.isalpha() == False:
		return False
	for i in range(0, lenS):
		if stringS[i] == '*':
			wildcardExists = True
			wildcardIndex = i
			difference = lenS - wildcardIndex - 1
			break
	if wildcardExists == False:
		if stringS != stringT:
			return False
	elif wildcardExists == True:
		tempstringS = stringS.replace('*', '')
		if tempstringS == stringT:
			return True
	if stringT[wildcardIndex:].isalpha():
		stringS = stringS[:wildcardIndex] + stringT[wildcardIndex:lenT - difference] + stringS[wildcardIndex:]
		stringS = stringS.replace('*', '')
		if stringS == stringT:
			return True
	return False
lengths = input().split(' ')
stringS = input()
stringT = input()
obtainable = obtainString(int(lengths[0]), int(lengths[1]), stringS, stringT)
if obtainable == True:
	print('YES')
else:
	print('NO')


import sys
(n, m) = map(int, input().split())
s = str(input())
t = str(input())
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
	sys.exit(0)
(l, r) = s.split('*')
if t.startswith(l) and t.endswith(r) and (len(t) >= len(l) + len(r)):
	print('YES')
else:
	print('NO')


def cout(x):
	if x:
		print('YES')
	else:
		print('NO')
(a, b) = map(int, input().split())
c = input()
d = input()
if '*' not in c:
	cout(c == d)
else:
	(x, y) = c.split('*')
	cout(d.startswith(x) and d[len(x):].endswith(y))


put = lambda : tuple(map(int, input().split()))
(n, m) = put()
s = input()
t = input()
x = s.count('*')
if x == 0 and s != t:
	print('NO')
elif n - x > m:
	print('NO')
elif x == 0 and s == t:
	print('YES')
else:
	ind = s.index('*')
	if s[:ind] == t[:ind]:
		sub = s[ind + 1:]
		if t.rfind(sub) == m - len(sub):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


(a, b) = [int(x) for x in input().split()]
s = str(input())
t = str(input())
wld = s.find('*')
if a > b + 1:
	print('NO')
elif wld == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	sbegin = s[0:wld]
	send = s[wld + 1:]
	tbegin = t[0:wld]
	tend = t[len(t) - len(send):]
	if sbegin == tbegin and send == tend:
		print('YES')
	else:
		print('NO')


(sl, tl) = [int(x) for x in input().split()]
s = input()
t = input()
sa = s.split('*')
ans = 'No'
if len(sa) == 1 and s == t:
	ans = 'yes'
if len(sa) == 2 and len(sa[0]) + len(sa[1]) <= tl and t.startswith(sa[0]) and t.endswith(sa[1]):
	ans = 'yes'
print(ans)


(n, m) = [int(i) for i in input().split()]
s1 = input()
s2 = input()
i = 0
k = 0
if '*' in s1:
	t1 = s1[:s1.find('*')]
	t2 = s1[s1.find('*') + 1:]
	if m - len(t2) >= s1.find('*') and s2.find(t1) == 0 and (s2.rfind(t2) == m - len(t2)):
		print('YES')
	else:
		print('NO')
elif s1 == s2:
	print('YES')
else:
	print('NO')


(n, m) = (int(x) for x in input().split())
s = list(input())
t = list(input())
if n > m and s.count('*') == 0:
	print('NO')
	exit(0)
if n - m > 1:
	print('NO')
	exit(0)
k = -1
for i in range(n):
	if s[i] != '*':
		if s[i] != t[i]:
			print('NO')
			exit(0)
	else:
		k = i
		break
k1 = n - k - 1
if k == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
	exit(0)
for i in range(0, k1):
	if s[-i - 1] != t[-i - 1]:
		print('NO')
		exit(0)
print('YES')


(n, m) = map(int, input().split())
a = list(input())
b = list(input())
count = 0
if '*' in a:
	if n > m + 1:
		print('NO')
	else:
		s = a.index('*')
		for i in range(s):
			if a[i] != b[i]:
				count = 1
				break
		for j in range(n - s - 1):
			if a[-j - 1] != b[-j - 1]:
				count = 1
				break
		if count == 0:
			print('YES')
		else:
			print('NO')
elif a == b:
	print('YES')
else:
	print('NO')


input()
s = input()
t = input()
if s.count('*'):
	for i in range(len(s)):
		if s[i] == '*':
			print('YES' if s[0:i] == t[0:i] and s[i + 1:] == t[len(t) - len(s[i + 1:]):] and (i <= len(t) - len(s[i + 1:])) else 'NO')
			exit(0)
else:
	print('YES' if s == t else 'NO')


(n, m) = [int(x) for x in input().split()]
a = input()
b = input()
if '*' not in a:
	if a == b:
		print('YES')
	else:
		print('NO')
else:
	(part1, part2) = a.split('*')
	if b.startswith(part1) and b.endswith(part2) and (len(part1) + len(part2) <= len(b)):
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
a = input()
b = input()
if len(a) > len(b) + a.count('*'):
	exit(print('NO'))
if '*' in a:
	k = a.index('*')
	for i in range(k):
		if a[i] != b[i]:
			exit(print('NO'))
	for i in range(n - k - 1):
		if a[~i] != b[~i]:
			exit(print('NO'))
	print('YES')
else:
	print('YES' if a == b else 'NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
	exit(0)
z = s.index('*')
if m < n - 1:
	print('NO')
	exit(0)
if s[z + 1:] == t[len(t) - len(s[z + 1:]):] and s[:z] == t[:z]:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
a = input('')
b = input('')
t = list(a)
l = list(b)
f = 1
p = 0
k = 0
if n - 1 > m:
	print('NO')
elif '*' in a:
	w = t.index('*')
	for i in range(w):
		if not t[p] == l[p]:
			f = 0
			print('NO')
			break
		p = p + 1
	if f == 1:
		t.reverse()
		l.reverse()
		q = t.index('*')
		for lt in range(q):
			if t[k] != l[k]:
				print('NO')
				f = 0
				break
			k = k + 1
		if f == 1:
			print('YES')
elif a == b:
	print('YES')
else:
	print('NO')


import sys
import re
input()
s1 = input()
s2 = input()

def judge(s1, s2):
	if not '*' in s1:
		return s1 == s2
	else:
		if len(s1) > len(s2) + 1:
			return False
		s = str.split(s1, '*')
		return str.startswith(s2, s[0]) and str.endswith(s2, s[1])
print('YES' if judge(s1, s2) else 'NO')


input()
(s, t) = (input(), input())
try:
	(a, b) = s.split('*')
	r = t.startswith(a) and t[len(a):].endswith(b)
except:
	r = s == t
print(['NO', 'YES'][r])


(n, m) = input().split()
(n, m) = (int(n), int(m))
s = input()
t = input()
if '*' in s:
	s = s.split('*')
	s1 = s[0]
	s2 = s[1]
	if t.startswith(s1) and t[len(s1):].endswith(s2):
		print('YES')
	else:
		print('NO')
elif s == t:
	print('YES')
else:
	print('NO')


n = input()
s = input()
t = input()
p = s.find('*')
if p == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
	exit(0)
sl = len(s) - p - 1
if s[:p] == t[:p] and t[len(t) - sl:] == s[p + 1:] and (len(t) >= len(s) - 1):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
(s, t) = (input(), input())
splt = s.split('*')
if len(splt) > 1:
	(fst_s, scd_s) = (splt[0], splt[1])
	(fst_t, scd_t) = (t[:len(fst_s)], t[len(fst_s):])
	if fst_s == fst_t and len(scd_t) >= len(scd_s) and (scd_t[len(scd_t) - len(scd_s):] == scd_s):
		print('YES')
	else:
		print('NO')
elif s == t:
	print('YES')
else:
	print('NO')


(m, n) = map(int, input().split())
a = input()
b = input()
if a == b:
	print('YES')
elif len(a) - len(b) > 1:
	print('NO')
elif '*' in a:
	pos = a.find('*')
	temp1 = a[:pos]
	temp2 = a[pos + 1:]
	if b.endswith(temp2) and b.startswith(temp1):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


def solve(N, M, S, T):
	p = S.find('*')
	if p == -1:
		return S == T
	pre = S[:p]
	post = S[p + 1:]
	if not T.startswith(pre) or not T.endswith(post):
		return False
	if len(pre) + len(post) > M:
		return False
	rest = T[p:M - len(post)]
	return len([c for c in rest if not 'a' <= c <= 'z']) == 0

def main():
	(N, M) = [int(e) for e in input().split(' ')]
	S = input()
	T = input()
	print('YES' if solve(N, M, S, T) else 'NO')
main()


(n, m) = map(int, input().split())
if n - 1 > m:
	print('NO')
	exit(0)
s = input()
t = input()
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
	exit(0)
for i in range(n):
	if s[i] == '*':
		break
	if s[i] != t[i]:
		print('NO')
		exit(0)
i = n - 1
j = m - 1
while i >= 0 and j >= 0:
	if s[i] == '*':
		break
	if s[i] != t[j]:
		print('NO')
		exit(0)
	i -= 1
	j -= 1
print('YES')


input()
a = input()
b = input()
if '*' not in a:
	if a == b:
		print('YES')
	else:
		print('NO')
elif len(a) > len(b) + 1:
	print('NO')
else:
	i = a.find('*')
	l = a[:i]
	r = a[i + 1:]
	ind = b.find(l)
	if ind:
		print('NO')
	else:
		b = b[::-1]
		ind = b.find(r[::-1])
		if ind:
			print('NO')
		else:
			print('YES')


(n, m) = map(int, input().split())
s = input()
t = input()
f = 1
(i_, j_) = (-1, -1)
for i in range(n):
	if s[i] == '*':
		i_ = i
		break
if i_ == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
elif i_ > m:
	print('NO')
elif s[:i_] != t[:i_]:
	print('NO')
elif m - (n - i_ - 1) < 0:
	print('NO')
elif t[m - (n - i_) + 1:] != s[i_ + 1:]:
	print('NO')
else:
	j_ = m - n + i_
	if i_ - 1 <= j_:
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if s == t:
	print('YES')
elif '*' not in s:
	print('NO')
else:
	idx = s.find('*')
	if t.startswith(s[:idx]) and t.endswith(s[idx + 1:]) and (n <= m + 1):
		print('YES')
	else:
		print('NO')


(n, k) = map(int, input().split())
p = input()
y = input()
if '*' not in p:
	if p == y:
		print('YES')
		quit()
	else:
		print('NO')
		quit()
w = p.split('*')
if n > k + 1:
	print('NO')
elif w[0] == y[:len(w[0])] and w[1] == y[k - len(w[1]):]:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s1 = input()
s2 = input()
if m < n - 1:
	print('NO')
else:
	index = -1
	for i in range(n):
		if s1[i] == '*':
			index = i
	if index == -1:
		if n == m:
			flag = 0
			for i in range(n):
				if s1[i] != s2[i]:
					flag = 1
					break
			if flag == 1:
				print('NO')
			else:
				print('YES')
		else:
			print('NO')
	else:
		flag = 0
		for i in range(index):
			if s1[i] != s2[i]:
				flag = 1
				break
		if flag == 1:
			print('NO')
		else:
			for i in range(1, n - index):
				if s1[-i] != s2[-i]:
					flag = 1
					break
			if flag == 1:
				print('NO')
			else:
				print('YES')


firstinput = []
input_string = input()
list_a = input_string.split()
count = 0
while count < 2:
	firstinput.append(int(list_a[count]))
	count += 1
wordinput = str(input())
realword = str(input())
wordinputlist = list(wordinput.lower())
realwordlist = list(realword.lower())
if len(wordinputlist) - 1 > len(realwordlist):
	print('NO')
elif len(wordinputlist) == 1 and len(realwordlist) == 1:
	if wordinputlist[0] == '*':
		print('YES')
	elif wordinputlist[0] == realwordlist[0]:
		print('YES')
	else:
		print('NO')
elif '*' not in wordinputlist:
	if len(wordinputlist) == len(realwordlist):
		counter = 0
		start = 0
		while start < len(wordinputlist):
			if wordinputlist[start] != realwordlist[start]:
				counter += 1
			start += 1
		if counter > 0:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')
elif wordinputlist[0] == '*':
	counter = 0
	start = 1
	realwordstart = len(realwordlist) - len(wordinputlist) + 1
	while start < len(wordinputlist):
		if wordinputlist[start] != realwordlist[realwordstart]:
			counter += 1
		start += 1
		realwordstart += 1
	if counter > 0:
		print('NO')
	else:
		print('YES')
elif wordinputlist[len(wordinputlist) - 1] == '*':
	counter = 0
	start = 0
	realwordstart = 0
	while start < len(wordinputlist) - 1:
		if wordinputlist[start] != realwordlist[realwordstart]:
			counter += 1
		start += 1
		realwordstart += 1
	if counter > 0:
		print('NO')
	else:
		print('YES')
else:
	counter = 0
	start = 0
	loop = 0
	end1 = len(wordinputlist) - 1
	while loop < len(wordinputlist):
		if loop != len(wordinputlist) - 1 and wordinputlist[loop + 1] == '*':
			end = loop
		elif wordinputlist[loop] == '*':
			start1 = loop + 1
		loop += 1
	realwordstart = 0
	while start <= end:
		if wordinputlist[start] != realwordlist[realwordstart]:
			counter += 1
		start += 1
		realwordstart += 1
	realwordstart = len(realwordlist) - (end1 - start1) - 1
	while start1 <= end1:
		if wordinputlist[start1] != realwordlist[realwordstart]:
			counter += 1
		start1 += 1
		realwordstart += 1
	if counter > 0:
		print('NO')
	else:
		print('YES')


def main():
	(n, m) = map(int, input().split())
	s = input()
	t = input()
	if n - 1 > m:
		print('NO')
		return
	if n < m:
		if '*' not in s:
			print('NO')
			return
	if n > m:
		if '*' not in s:
			print('NO')
			return
	before = []
	for i in s:
		if i == '*':
			break
		before.append(i)
	after = []
	for i in range(n - 1, -1, -1):
		if s[i] == '*':
			break
		after.append(s[i])
	after.reverse()
	for i in range(len(before)):
		if before[i] != t[i]:
			print('NO')
			return
	for i in range(len(after)):
		if after[len(after) - 1 - i] != t[len(t) - 1 - i]:
			print('NO')
			return
	print('YES')
main()


(n, m) = map(int, input().split())
s = input()
t = input()
flags1 = 0
sett = 0
flags2 = n - 1
flagt1 = 0
flagt2 = m - 1
temp = -1
for i in range(n):
	if s[i] == '*':
		temp = i
		break
if temp == -1:
	if m != n:
		print('NO')
	else:
		for i in range(n):
			if s[i] != t[i]:
				sett = 1
		if sett == 1:
			print('NO')
		else:
			print('YES')
elif n - 1 > m:
	print('NO')
else:
	for i in range(0, temp):
		if s[i] != t[i]:
			sett = 1
			break
	if sett == 1:
		print('NO')
	else:
		count1 = n - temp - 1
		i = n - 1
		j = m - 1
		while count1:
			if s[i] != t[j]:
				sett = 1
				break
			else:
				i -= 1
				j -= 1
				count1 -= 1
		if sett == 1:
			print('NO')
		else:
			print('YES')


(n, m) = input().split()
n = int(n)
m = int(m)
s = input()
t = input()
if n <= m + 1:
	if '*' in s:
		i = s.index('*')
		pres = s[:i]
		sufs = s[i + 1:]
		x = len(sufs)
		pret = t[:i]
		suft = t[-1 * x:]
		fins = pres + sufs
		fint = pret + suft
		if fins == fint:
			print('YES')
		elif fins == '':
			print('YES')
		elif pres == pret and sufs == '':
			print('YES')
		elif sufs == suft and pres == '':
			print('YES')
		else:
			print('NO')
	elif s == t:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if '*' in s:
	(left, right) = s.split('*')
	r = t.startswith(left) and t.endswith(right) and (len(t) >= len(s) - 1)
else:
	r = s == t
print('YES' if r else 'NO')


(n, m) = [int(x) for x in input().split()]
s = input()
t = input()
if s == t:
	print('YES')
	exit()
if len(s) > len(t) and s.count('*') == 0:
	print('NO')
	exit()
if len(s) > len(t) + 1:
	print('NO')
	exit()
if s.count('*') == 0:
	print('NO')
	exit()
for i in range(len(s)):
	if s[i] == '*':
		break
	if s[i] != t[i]:
		print('NO')
		exit()
i = len(s) - 1
j = len(t) - 1
while True:
	if s[i] == '*':
		break
	if s[i] != t[j]:
		print('NO')
		exit()
	i -= 1
	j -= 1
print('YES')


(a, b) = list(map(int, input().split()))
s = input()
t = input()
x = s.find('*')
if x == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
elif a > b + 1:
	print('NO')
else:
	sb4 = s[0:x]
	safter = s[x + 1:]
	tb4 = t[0:x]
	tafter = t[x:]
	if sb4 == tb4 and safter == tafter[len(tafter) - len(safter):]:
		print('YES')
	else:
		print('NO')


(a, b) = map(int, input().split())
(x, y) = (input(), input())
if '*' not in x:
	print('YES' if x == y else 'NO')
	exit()
if a > b + 1:
	print('NO')
else:
	(m, n) = x.split('*')
	print('YES' if (m == y[:len(m)] or len(m) == 0) and (len(n) == 0 or n == y[-len(n):]) else 'NO')


(n, m) = map(int, input().split())
s = input()
t = input()
k = s.find('*')
if k == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	tail_len = n - k - 1
	if tail_len == 0:
		tail = ''
	else:
		tail = t[-tail_len:]
	if s[:k] == t[:k] and s[k + 1:] == tail and (n - 1 <= m):
		print('YES')
	else:
		print('NO')


def main():
	insert = input().split()
	x = int(insert[0])
	y = int(insert[1])
	input1 = input()
	input2 = input()
	star_exists = False
	star_posiition = 0
	same = True
	for i in range(0, x):
		if input1[i] == '*':
			star_exists = True
			star_posiition = i
	dataDiff = y - x
	if dataDiff < -1:
		same = False
	elif star_exists:
		for i in range(0, star_posiition):
			if not input1[i] == input2[i]:
				same = False
				break
		for i in range(x - 1, star_posiition, -1):
			if not input2[i + dataDiff] == input1[i]:
				same = False
				break
	elif not input1 == input2:
		same = False
	if same == True:
		print('YES')
	else:
		print('NO')
main()


(n, m) = map(int, input().split())
(s, t) = (input(), input())
if n > m + 1:
	print('NO')
elif '*' in s:
	(start, end) = s.split('*')
	print('YES' if t.startswith(start) and t.endswith(end) else 'NO')
else:
	print('YES' if s == t else 'NO')


(n, m) = map(int, input().split())
s = input()
t = input()
ind = -1
for i in range(len(s)):
	if s[i] == '*':
		ind = i
		break
if ind == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
	exit()
if m < n - 1:
	print('NO')
	exit()
if s[:ind] == t[:ind] and s[ind + 1:] == t[m - n + ind + 1:]:
	print('YES')
else:
	print('NO')


from sys import stdin, stdout

def rint():
	return map(int, stdin.readline().split())
(n, m) = rint()
s = input()
t = input()
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
	exit()
if n == 1:
	print('YES')
	exit()
if s[-1] == '*':
	if s[:-1] == t[:n - 1]:
		print('YES')
	else:
		print('NO')
	exit()
if s[0] == '*':
	if s[1:] == t[m - (n - 1):m]:
		print('YES')
	else:
		print('NO')
	exit()
ss = []
ss = list(s.split('*'))
if ss[0] == t[0:len(ss[0])] and ss[1] == t[m - len(ss[1]):m] and (m >= n - 1):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if s == t:
	print('YES')
elif '*' in s:
	i = s.index('*')
	if n <= m + 1 and s[:i] == t[:i] and (s[i + 1:] == t[m - (n - i) + 1:]):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


import sys
(n, m) = map(int, input().split())
s = input()
t = input()
l = [-1]
ans = []
for i in range(n):
	if s[i] == '*':
		l.append(i)
a = max(l)
if max(l) == -1:
	if s == t:
		ans.append('YES')
	else:
		ans.append('NO')
elif n - a - 1 <= m - a:
	if s[:a] != t[:a]:
		ans.append('NO')
	else:
		p = s[n:a:-1]
		x = len(p)
		if x == 0:
			ans.append('YES')
			print(*ans)
			sys.exit()
		yu = t[m:m - x - 1:-1]
		if len(t[m:m - x - 1:-1]) == 0 and a == 0:
			yu = t
		if yu == p:
			ans.append('YES')
		else:
			ans.append('NO')
else:
	ans.append('NO')
print(*ans)


(n, m) = map(int, input().split())
s = input()
t = input()
if n - 1 > m:
	print('NO')
	exit()
try:
	c = s.index('*')
except ValueError:
	if s == t:
		print('YES')
	else:
		print('NO')
	exit()
if c == 0:
	if s[::-1][:len(s) - 1] == t[::-1][:len(s) - 1]:
		print('YES')
	else:
		print('NO')
elif c == len(s) - 1:
	if s[:len(s) - 1] == t[:len(s) - 1]:
		print('YES')
	else:
		print('NO')
elif s[:c] == t[:c] and s[c + 1:][::-1] == t[::-1][:len(s) - 1 - c]:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if '*' not in s:
	print('YES' if s == t else 'NO')
elif s[-1] == '*':
	print('YES' if t.startswith(s[:-1]) else 'NO')
else:
	(u, v) = s.split('*')
	print('YES' if t[:-len(v)].startswith(u) and t[len(u):].endswith(v) else 'NO')


(n, m) = map(int, input().split())
s = input()
t = input()
sp = s.split('*')
print(('NO', 'YES')[t.startswith(sp[0]) and t.endswith(sp[-1]) and (s == t) * ('*' not in s) + (len(t) >= len(sp[0]) + len(sp[-1]) * ('*' in s)) * ('*' in s)])


(n, m) = map(int, input().split())
(s, t) = (input(), input())
if n > m + 1:
	print('NO')
elif s == t:
	print('YES')
elif '*' not in s:
	print('NO')
elif s == '*':
	print('YES')
else:
	l = s.split('*')
	(a, b) = (0, 0)
	if t[:len(l[0])] == l[0] or l[0] == '':
		a += 1
	if t[-len(l[-1]):] == l[-1] or l[-1] == '':
		b += 1
	if a == 1 and b == 1:
		print('YES')
	else:
		print('NO')


input()
s = input()
t = input()
s = ' ' + s + ' '
t = ' ' + t + ' '
if '*' in s:
	idx = s.find('*')
	(prefix, suffix) = (s[:idx], s[idx + 1:])
	print('YES' if len(s) - 1 <= len(t) and prefix == t[:len(prefix)] and (suffix == t[-len(suffix):]) else 'NO')
else:
	print('YES' if s == t else 'NO')


(n, m) = map(int, input().split())
stroka1 = str(input())
stroka2 = str(input())
if '*' in stroka1:
	per = stroka1[:stroka1.index('*')]
	vtor = stroka1[stroka1.index('*') + 1:]
	if len(stroka1) - len(stroka2) <= 1 and stroka2[:len(per)] == per and (stroka2[::-1][:len(vtor)][::-1] == vtor):
		print('YES')
	else:
		print('NO')
elif stroka1 == stroka2:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
a = input()
b = input()
gwiazdka = a.find('*')
if n > m + 1:
	print('NO')
	exit()
if gwiazdka == -1:
	print('YES' if a == b else 'NO')
	exit()
for i in range(gwiazdka):
	if a[i] != b[i]:
		print('NO')
		exit()
for i in range(n - gwiazdka - 1):
	if a[-i - 1] != b[-i - 1]:
		print('NO')
		exit()
print('YES')


import sys, string
(n, m) = map(int, sys.stdin.readline().split())
s = list(sys.stdin.readline().rstrip())
t = list(sys.stdin.readline().rstrip())
idx = -1
for i in range(n):
	if s[i] == '*':
		idx = i
if idx == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
elif m < n - 1:
	print('NO')
else:
	s_left = s[0:idx]
	s_right = s[idx + 1:n]
	a = len(s_left)
	b = len(s_right)
	t_left = []
	t_right = []
	for i in range(a):
		t_left.append(t[i])
		t[i] = ''
	for i in range(b):
		t_right.append(t[m - i - 1])
	if s_left == t_left and s_right == t_right[::-1]:
		print('YES')
	else:
		print('NO')


(n, m) = input().split()
n = int(n)
m = int(m)
s = input()
t = input()
star = s.find('*')
if star > -1 and m >= n - 1:
	r = t.rfind(s[star + 1:])
	if r > -1 and r + len(t[r:]) == m and (t[:star] + '*' + t[star + m - n + 1:] == s):
		print('YES')
	else:
		print('NO')
elif star == -1 and m == n:
	if t == s:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if n - 1 > m:
	print('NO')
else:
	x = s.find('*')
	if x == -1:
		if s != t:
			print('NO')
		else:
			print('YES')
	elif s[:x] == t[:x] and s[x + 1:] == t[x + (m - n) + 1:]:
		print('YES')
	else:
		print('NO')


def patternMatching(first, second):
	if first == second:
		return 'YES'
	if len(second) < len(first) - 1 or first.find('*') == -1:
		return 'NO'
	stop = None
	for i in range(len(first)):
		if first[i] == '*':
			stop = len(second) - i - 1
			break
		if i >= len(second) or first[i] != second[i]:
			return 'NO'
	first = first[::-1]
	second = second[::-1]
	for i in range(len(first)):
		if first[i] == '*':
			break
		if i > stop or first[i] != second[i]:
			return 'NO'
	return 'YES'
lengths = input().split(' ')
(a, b) = (lengths[0], lengths[1])
first = input()
second = input()
print(patternMatching(first, second))


n = input()
s = input()
t = input()
if '*' in s:
	arr = s.split('*')
	if t.startswith(arr[0]) and t.endswith(arr[1]) and (len(arr[0]) + len(arr[1]) <= len(t)):
		print('YES')
	else:
		print('NO')
elif s == t:
	print('YES')
else:
	print('NO')


readints = lambda : map(int, input().strip('\n').split())
readstr = lambda : input().strip('\n')

def printlist(lst):
	buf = ''
	for i in range(len(lst) - 1):
		buf += str(lst[i]) + ' '
	buf += str(lst[-1])
	print(buf)
(n, m) = readints()
s = readstr()
t = readstr()

def isMatch(s, t):
	if '*' not in s:
		return s == t
	star = s.find('*')
	left = s[:star]
	right = s[star + 1:]
	l = len(left)
	r = len(t) - len(right)
	if r < 0 or r - l < 0:
		return False
	middle = t[l:r]
	return left + middle + right == t
if isMatch(s, t):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
s = list(s)
t = list(t)
if '*' in s:
	p = s.index('*') + 1
	q = len(s[s.index('*') + 1:])
	if len(s) > len(t) + 1:
		print('NO')
	elif s[0:s.index('*')] == t[0:s.index('*')] and s[s.index('*') + 1:] == t[len(t) - q:len(t)]:
		print('YES')
	else:
		print('NO')
elif '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
a = input().split('*')
b = input()
print('YES' if n == m and a[0] == b else 'YES' if len(a) == 2 and m - n >= -1 and (b[:len(a[0])] == a[0]) and (b[m - len(a[1]):] == a[1]) else 'NO')


n_m = input().split()
n = int(n_m[0])
m = int(n_m[1])
s = input()
t = input()
answer = 'YES'
symbol = '*'
if symbol in s:
	s_list = list(s)
	if len(s_list) == 1:
		answer = 'YES'
	else:
		star_index = s_list.index(symbol)
		if star_index == 0:
			s_right = s[1:]
			if not t.endswith(s_right):
				answer = 'NO'
		elif star_index == n - 1:
			s_left = s[:-1]
			if not t.startswith(s_left):
				answer = 'NO'
		else:
			s_left = s[:star_index]
			s_right = s[star_index + 1:]
			if not (t.startswith(s_left) and t.endswith(s_right)):
				answer = 'NO'
			elif n - m > 1:
				answer = 'NO'
elif s != t:
	answer = 'NO'
print(answer)


(n, m) = [int(s) for s in input().split()]
s = input()
t = input()
gg = -1
gg = s.find('*')
if gg == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
	exit()
s1 = s[:gg]
s2 = s[gg + 1:]
if t.find(s1) == 0 and t[::-1].find(s2[::-1]) == 0 and (len(t) + 2 > len(s)):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if s == '*':
	print('YES')
elif s.count('*') is 0:
	if s == t:
		print('YES')
	else:
		print('NO')
elif s[0] is '*':
	check = t[-(n - 1):]
	if check == s[1:]:
		print('YES')
	else:
		print('NO')
elif s[-1] is '*':
	check1 = s[:n - 1]
	check2 = t[:n - 1]
	if check1 == check2:
		print('YES')
	else:
		print('NO')
else:
	(s1, s2) = s.split('*')
	len_s1 = len(s1)
	len_s2 = len(s2)
	if len_s1 + len_s2 > m:
		print('NO')
	else:
		x = t[:len_s1]
		y = t[-len_s2:]
		if x == s1 and y == s2:
			print('YES')
		else:
			print('NO')


In = input().split()
(n, m) = (int(In[0]), int(In[1]))
s1 = input()
s2 = input()
Match = True
if n > m and abs(n - m) > 1:
	Match = False
index = -1
j = 0
for i in range(n):
	if s1[i] == '*':
		index = i
		break
	if j != m:
		if s1[i] != s2[j]:
			Match = False
			break
		j += 1
if index == -1 and Match == True:
	if n == m:
		print('YES')
	else:
		print('NO')
else:
	i = n - 1
	j = m - 1
	while i != index:
		if j == -1:
			Match = False
			break
		if s1[i] != s2[j]:
			Match = False
			break
		i -= 1
		j -= 1
	if Match:
		print('YES')
	else:
		print('NO')


num = input()
(num1, num2) = num.split()
num1 = int(num1)
num2 = int(num2)
word1 = input()
word2 = input()
if num1 > num2 + 1:
	print('NO')
elif not '*' in word1:
	if word1 == word2:
		print('YES')
	else:
		print('NO')
else:
	(word1_1, word1_2) = word1.split('*')
	len_word1_1 = len(word1_1)
	len_word1_2 = len(word1_2)
	if word2[:len_word1_1] == word1_1 and word2[num2 - len_word1_2:] == word1_2:
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if not '*' in s:
	print(s == t and 'YES' or 'NO')
else:
	(s1, s2) = s.split('*')
	print(t.islower() and len(s) - 1 <= len(t) and t.startswith(s1) and t.endswith(s2) and 'YES' or 'NO')


def fitSearch(S, T):
	parts_S = S.split('*')
	if len(parts_S) == 1:
		if S == T:
			return 'YES'
		else:
			return 'NO'
	try:
		firstIndex = 0
		while firstIndex < len(parts_S[0]):
			if T[firstIndex] != parts_S[0][firstIndex]:
				return 'NO'
			firstIndex += 1
		secondIndex = len(parts_S[1]) - 1
		secondIndexT = len(T) - 1
		while secondIndex >= 0:
			if T[secondIndexT] != parts_S[1][secondIndex]:
				return 'NO'
			secondIndex -= 1
			secondIndexT -= 1
		if len(parts_S[0]) + len(parts_S[1]) > len(T):
			return 'NO'
	except:
		return 'NO'
	return 'YES'
(sizeS, sizeT) = tuple(map(int, input().split(' ')))
S = input()
T = input()
print(fitSearch(S, T))


(n, m) = [int(x) for x in input().split()]
s = input()
t = input()
if '*' in s:
	lcp = 0
	p = 0
	while p < min(n, m) and s[p] == t[p]:
		lcp += 1
		p += 1
	lcs = 0
	p1 = n - 1
	p2 = m - 1
	while p1 >= 0 and p2 >= 0 and (s[p1] == t[p2]):
		lcs += 1
		p1 -= 1
		p2 -= 1
	ans = 'YES'
	if min(lcp + lcs, m) < n - 1:
		ans = 'NO'
else:
	ans = 'YES'
	if s != t:
		ans = 'NO'
print(ans)


(n, m) = map(int, input().split())
(a, b) = (input(), input())
if '*' not in a:
	print('YES' if a == b else 'NO')
else:
	(l, r) = a.split('*')
	if b.startswith(l) and b.endswith(r) and (len(l) + len(r) <= len(b)):
		print('YES')
	else:
		print('NO')


kek = input()
s = input()
t = input()
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	index = s.find('*')
	cnt = len(s) - index - 1
	if t[:index] == s[:index] and t[len(t) - cnt:] == s[index + 1:] and (cnt <= len(t) - index):
		print('YES')
	else:
		print('NO')


(n, m) = [int(x) for x in input().split()]
s = str(input())
t = str(input())
if s.count('*') == 0:
	if s == t:
		print('YES')
	else:
		print('NO')
elif n == m + 1 and s[:s.index('*')] + s[s.index('*') + 1:] == t:
	print('YES')
elif n > m + 1:
	print('NO')
elif n < m + 1 and s[:s.index('*')] + s[s.index('*') + 1:] == t[:s.index('*')] + t[s.index('*') + 1 + m - n:]:
	print('YES')
else:
	print('NO')


from sys import stdin, stdout
input = lambda : stdin.readline().rstrip()
write = stdout.write

def main():
	(N, M) = map(int, input().split())
	S = input()
	T = input()
	if not T.isalpha():
		print('NO')
		return
	if '*' in S:
		if N - 1 > M:
			print('NO')
			return
	elif S != T:
		print('NO')
		return
	s = S.split('*')
	for (i, s_) in enumerate(s[0]):
		if not s_:
			continue
		if s_ != T[i]:
			print('NO')
			return
	if len(s) > 1:
		for (i, s_) in enumerate(s[1], start=1):
			if not s_:
				continue
			if s[1][-i] != T[-i]:
				print('NO')
				return
	print('YES')
main()


(n, m) = map(int, input().strip().split())
s = input().strip()
t = input().strip()
try:
	(start, end) = s.split('*')
	if t.startswith(start):
		t = t[len(start):]
		print('YES' if t.endswith(end) else 'NO')
	else:
		print('NO')
except ValueError:
	print('YES' if s == t else 'NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if s.find('*') == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
elif m < n - 1:
	print('NO')
else:
	x = s.find('*')
	l2 = len(s[x + 1:n])
	l1 = len(s[0:x])
	if s[x + 1:n] == t[m - l2:m] and s[0:x] == t[0:l1]:
		print('YES')
	else:
		print('NO')


(a, b) = map(int, input().split())
s1 = str(input())
s2 = str(input())
try:
	l = s1.index('*')
	if s1[0:l:1] == s2[0:l:1] and s1[-1:-len(s1) + l:-1] == s2[-1:-len(s1) + l:-1]:
		if len(s2) >= len(s1) - 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
except:
	if s1 == s2:
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if m < n - 1:
	print('NO')
elif '*' in s:
	i = 0
	f = 1
	while i < n and s[i] != '*':
		if s[i] != t[i]:
			f = 0
			break
		else:
			i = i + 1
	if f == 1:
		i = n - 1
		j = m - 1
		while s[i] != '*':
			if s[i] != t[j]:
				f = 0
				break
			else:
				i = i - 1
				j = j - 1
		if f == 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
elif s == t:
	print('YES')
else:
	print('NO')


num = input()
nums = int(num.split()[0])
numt = int(num.split()[1])
s = str(input())
t = str(input())
answer = ''
detect = -1
pre = 1
if nums > numt:
	if nums - numt != 1:
		pre = 0
if s == t:
	print('YES')
elif pre != 0:
	for i in range(nums):
		if s[i] == '*':
			detect = i
			break
		if detect == '-1':
			answer = 'NO'
			print('NO')
	if answer != 'NO':
		newleftstr = t[:detect]
		newrightstr = t[numt - (nums - detect) + 1:]
		newallstr = newleftstr + '*' + newrightstr
		if s == newallstr:
			print('YES')
		else:
			print('NO')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if s == t:
	print('YES')
elif s.count('*') > 0:
	k = s.find('*')
	s1 = s[:k]
	s2 = t[:k]
	s3 = s[k + 1:]
	s4 = t[m - n + k + 1:]
	if n > m + 1:
		print('NO')
		exit()
	if s1 == s2 and s3 == s4:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


def cin(obj=list, type=int, sep=' '):
	return obj(map(type, input().split(sep)))
(n, m) = cin()
(s, t) = (input(), input())
pos = s.find('*')
if pos == -1:
	if n != m:
		print('NO')
		quit()
	else:
		pos = n
if t.startswith(s[:pos]) and t.endswith(s[pos + 1:]) and (pos + n - pos - 1 <= m):
	print('YES')
else:
	print('NO')


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

def f():
	if '*' not in s:
		return s == t
	if n - 1 > m:
		return False
	x = s.find('*')
	return s[:x] == t[:x] and s[x + 1:] == t[m - (n - 1 - x):]
if f():
	print('YES')
else:
	print('NO')


(m, n) = map(int, input().split())
s = input()
t = input()
if s.find('*') != -1:
	(ls, rs) = s.split('*')
	if len(ls) == 0:
		if len(rs) == 0:
			print('YES')
		elif t.rfind(rs) + len(rs) == len(t):
			print('YES')
		else:
			print('NO')
	elif ls[0] == t[0]:
		if t.find(ls) != -1:
			d = t.find(ls)
			if t[d + len(ls):].rfind(rs) != -1:
				if t[d + len(ls):].rfind(rs) + len(rs) == len(t[d + len(ls):]):
					print('YES')
				else:
					print('NO')
			else:
				print('NO')
		else:
			print('NO')
	else:
		print('NO')
elif s == t:
	print('YES')
else:
	print('NO')


numbers = list(map(int, input().split()))
n = numbers[0]
m = numbers[1]
s = input()
t = input()
if n > m + 1:
	print('NO')
elif n == 1 and n == m and (s != '*') and (s != t):
	print('NO')
elif n == m and s == '*':
	print('YES')
elif n == m and s == t:
	print('YES')
else:
	newS = s.split('*')
	if len(newS) == 1:
		if newS[0] == t:
			print('YES')
		elif n == m and t[0:len(newS[0])] == newS[0]:
			print('YES')
		else:
			print('NO')
	else:
		lenSt = len(newS[0])
		lenDr = len(newS[1])
		if t[0:lenSt] == newS[0] and t[-lenDr:] == newS[1]:
			print('YES')
		elif t[0:lenSt] == newS[0] and lenDr == 0:
			print('YES')
		elif n == m and lenDr == 0 and (t[0:lenSt - 1] == newS[0]):
			print('YES')
		else:
			print('NO')


(n, m) = [int(x) for x in input().split()]
s = input()
t = input()
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	sp1 = s[:s.index('*')]
	sp2 = s[s.index('*') + 1:]
	if t[0:len(sp1)] == sp1 and t[m - len(sp2):] == sp2 and (len(sp1) - 1 < m - len(sp2)):
		print('YES')
	else:
		print('NO')


(n, m) = [int(j) for j in input().split()]
s = input()
t = input()
if s == '*':
	print('YES')
	exit(0)
if len(s) - 1 > len(t):
	print('NO')
	exit(0)
a = s.split('*')
if len(a) == 1 and s != t:
	print('NO')
	exit(0)
elif len(a) == 1 and s == t:
	print('YES')
	exit(0)
if len(a) == 2:
	s1 = t[:len(a[0])]
	s2 = t[-len(a[1]):]
	if len(a[0]) == 0:
		if s2 == a[0] + a[1]:
			print('YES')
			exit(0)
		else:
			print('NO')
			exit(0)
	if len(a[1]) == 0:
		if s1 == a[0] + a[1]:
			print('YES')
			exit(0)
		else:
			print('NO')
			exit(0)
	if s1 + s2 == a[0] + a[1]:
		print('YES')
	else:
		print('NO')


(formatLen, toCheckLen) = [int(x) for x in input().split(' ')]
format = input()
toCheck = input()
if '*' not in format:
	if format == toCheck:
		print('YES')
	else:
		print('NO')
	exit()
if not toCheck.isalpha():
	print('NO')
	exit()
(start, end) = format.split('*')
if toCheckLen - len(end) <= len(start) - 1:
	print('NO')
	exit()
if not toCheck.startswith(start) or not toCheck.endswith(end):
	print('NO')
	exit()
print('YES')


(n, m) = map(int, input().split())
s = input()
t = input()
g = 1
if s.count('*') == 0 and len(s) != len(t):
	print('NO')
	g = 0
if len(s) - 1 > len(t):
	print('NO')
	g = 0
if g:
	if t.startswith(s[:s.find('*')]) and t.endswith(s[s.find('*') + 1:]):
		print('YES')
	else:
		print('NO')


import re
(n, m) = map(int, input().split())
s = input()
t = input()
if s.find('*') == -1:
	print('YES' if s == t else 'NO')
	exit(0)
s = s.split('*')
if t.startswith(s[0]) and t.endswith(s[1]) and (len(t) >= sum(map(len, s))):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = list(input())
t = list(input())
a = s.count('*')
c = n
if a == 1:
	c = s.index('*')
b = m - n
if c != n:
	if s[:c] == t[:c] and s[c + 1:] == t[m - (n - c - 1):] and (m - n + c + 1 >= c):
		print('YES')
		exit(0)
	else:
		print('NO')
		exit(0)
elif s == t:
	print('YES')
	exit(0)
else:
	print('NO')
	exit(0)


(s, t) = map(int, input().split())
str_1 = str(input())
str_2 = str(input())
if s < t:
	try:
		str_1 = str_1[:str_1.index('*') + 1] + '*' * abs(s - t) + str_1[str_1.index('*') + 1:]
		is_redact = 'YES'
		for i in range(t):
			if str_1[i] != '*':
				if str_1[i] == str_2[i]:
					pass
				else:
					is_redact = 'NO'
		print(is_redact)
	except:
		print('NO')
elif s > t:
	str_1b = str_1.replace('*', '')
	if str_1b == str_2:
		print('YES')
	else:
		print('NO')
elif str_1 == str_2:
	print('YES')
else:
	is_redact = 'YES'
	for i in range(t):
		if str_1[i] != '*':
			if str_1[i] == str_2[i]:
				pass
			else:
				is_redact = 'NO'
	print(is_redact)


(n, m) = [int(i) for i in input().split()]
menor = min(n, m)
s = input()
t = input()

def verifica():
	if not '*' in s:
		if s == t:
			return 'YES'
		else:
			return 'NO'
	if n - m > 1:
		return 'NO'
	for i in range(menor):
		if not s[i] == '*':
			if s[i] != t[i]:
				return 'NO'
		if s[i] == '*':
			break
	for i in range(1, menor):
		if not s[-i] == '*':
			if s[-i] != t[-i]:
				return 'NO'
		if s[-i] == '*':
			break
	return 'YES'
print(verifica())


import sys
a = input()
a = input()
b = input()
index = a.find('*')
tail = len(a) - index - 1
if index == -1 or len(b) < len(a) - 1:
	print('YES' if a == b else 'NO')
elif a[:index] == b[:index] and (a[-tail:] == b[-tail:] or tail == 0):
	print('YES')
else:
	print('NO')


def sol():
	(S, T) = [int(x) for x in input().split(' ')]
	s = input()
	t = input()
	if not '*' in s:
		return s == t
	(one, two) = s.split('*')
	if T < S - 1:
		return False
	t_one = t[:len(one)] == one or one == ''
	t_two = t[-1 * len(two):] == two or two == ''
	return t_one and t_two
ans = sol()
print('YES' if ans else 'NO')


(n, m) = map(int, input().split())
s = str(input())
t = str(input())
if '*' not in s:
	print('NO' if s != t else 'YES')
elif s == '*':
	print('YES')
elif s.index('*') == 0:
	print('YES' if t[-len(s) + 1:] == s[1:] else 'NO')
elif s[-1] == '*':
	print('YES' if t.find(s[:-1]) == 0 else 'NO')
else:
	(a, b) = s.split('*')
	x = t.find(a)
	t = t[:x] + t[x + len(a):]
	print('YES' if b in t and t.find(b) + len(b) == len(t) and (x == 0) else 'NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if n < m:
	flag = False
	for i in range(n):
		if s[i] == '*':
			flag = True
			if i == n - 1:
				if s[:i] == t[:i]:
					print('YES')
					break
				else:
					print('NO')
					break
			elif s[:i] == t[:i] and s[i + 1:] == t[-len(s[i + 1:]):]:
				print('YES')
				break
			else:
				print('NO')
				break
	if not flag:
		if s == t:
			print('YES')
		else:
			print('NO')
elif n == m:
	q = ''
	for i in range(n):
		if s[i] == '*':
			q += t[i]
		else:
			q += s[i]
	if q == t:
		print('YES')
	else:
		print('NO')
else:
	q = ''
	for i in range(n):
		if s[i] == '*':
			continue
		else:
			q += s[i]
	if q == t:
		print('YES')
	else:
		print('NO')


from string import printable
(n, m) = input().split(' ')
s = input()
t = input()
if int(n) > int(int(m) + 1):
	print('NO')
	exit(0)
if int(n) <= int(int(m) + 1):
	if '*' in s:
		x = s.split('*')
		h = len(x[1])
		z = len(x[0])
		if x[0] == t[:z] and x[1] == t[len(t) - h:]:
			print('YES')
		else:
			print('NO')
	elif s != t:
		print('NO')
	else:
		print('YES')


(a, b) = input().split()
a = input()
b = input()
if '*' in a:
	(c, d) = a.split('*')
	print('YES' if b.startswith(c) and b.endswith(d) and (len(a) - 1 <= len(b)) else 'NO')
else:
	print('YES' if a == b else 'NO')


_ = input()
s = input()
t = input()
p = s.find('*')
l = len(s) - p - 1
print('YES' if (s == t if p < 0 else p + l <= len(t) and (not p or s[:p] == t[:p]) and (not l or s[-l:] == t[-l:])) else 'NO')


(n, m) = list(map(int, input().split()))
s = input()
t = input()
if '*' not in s:
	ans = 'YES' if s == t else 'NO'
	print(ans)
elif n > m + 1:
	print('NO')
else:
	(p, q) = s.split('*')
	flg = True
	if len(p) > 0 and t[:len(p)] != p:
		flg = False
	if len(q) > 0 and t[-len(q):] != q:
		flg = False
	ans = 'YES' if flg else 'NO'
	print(ans)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
s = input()
t = input()
ck = 0
res = 0
mark1 = 0
mark2 = 0
for i in range(0, n):
	if s[i] == '*':
		ck = 1
if ck == 0:
	if s == t:
		print('YES')
		exit()
	else:
		print('NO')
		exit()
for i in range(0, n):
	if s[i] == '*':
		mark1 = i - 1
		break
	if i < m and s[i] != t[i]:
		print('NO')
		exit()
for i in range(n - 1, -1, -1):
	if s[i] == '*':
		mark2 = m - (n - i)
		break
	if m - (n - i) >= 0:
		if s[i] != t[m - (n - i)]:
			print('NO')
			exit()
if mark1 > mark2:
	print('NO')
	exit()
print('YES')


first = input()
f = input()
word = input()
if '*' not in f:
	if f == word:
		print('YES')
	else:
		print('NO')
else:
	(a, b) = f.split('*')
	if word.startswith(a) and word.endswith(b) and (len(a + b) <= len(word)):
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if m >= n - 1 and s[:s.find('*')] == t[:s.find('*')] and (s[s.find('*') + 1:] == t[len(t) - len(s) + s.find('*') + 1:]):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	ind = s.index('*')
	if s[0:ind] + s[ind + 1:] == t:
		print('YES')
	else:
		tmp = s[0:ind] + t[ind:m - n + ind + 1] + s[ind + 1:]
		if tmp == t:
			print('YES')
		else:
			print('NO')


(n, m) = [int(x) for x in input().split()]
s = str(input())
t = str(input())
if n > m + 1:
	print('NO')
elif not '*' in s and s != t:
	print('NO')
else:
	no = False
	for i in range(n):
		if s[i] != '*':
			if s[i] != t[i]:
				print('NO')
				no = True
				break
		else:
			if i < m and (not t[i].isalpha()):
				print('NO')
				no = True
			break
	if not no:
		min = min(m, n)
		for i in range(1, min):
			if s[-i] != '*':
				if s[-i] != t[-i]:
					print('NO')
					no = True
					break
			else:
				break
		if not no:
			print('YES')


(n, m) = map(int, input().split())
s = list(map(str, input().split('*')))
t = input()
if len(s) == 1:
	if s[0] == t:
		print('YES')
	else:
		print('NO')
elif m - n < -1:
	print('NO')
elif s[0] == t[0:len(s[0])] and s[1] == t[m - len(s[1]):m]:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
try:
	i = s.index('*')
	(Ls, Rs) = (s[:i], s[i + 1:])
	(Lt, Rt) = (t[:i], t[len(t) - len(Rs):])
	if Ls == Lt and Rs == Rt:
		if len(Lt + Rt) > len(t):
			print('NO')
		else:
			print('YES')
	else:
		print('NO')
except:
	if s == t:
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
s1 = input()
s2 = input()
if '*' in s1 and len(s1) <= len(s2) + 1:
	d = 1
	i = 0
	while s1[i] != '*':
		if s1[i] != s2[i]:
			d = 0
			break
		else:
			i += 1
	i = -1
	while d and s1[i] != '*':
		if s1[i] != s2[i]:
			d = 0
			break
		else:
			i -= 1
elif s1 == s2:
	d = 1
else:
	d = 0
if d:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s1 = str(input())
s2 = str(input())
if '*' in s1:
	if n - 1 > m:
		print('NO')
	else:
		flag = 0
		i = 0
		while i < len(s1) and i < len(s2) and (s1[i] != '*'):
			if s1[i] != s2[i]:
				flag = 1
				break
			i += 1
		if flag == 1:
			print('NO')
		elif i == len(s2):
			if s1[-1] == '*':
				print('YES')
			else:
				print('NO')
		else:
			j = len(s1) - 1
			k = len(s2) - 1
			while k >= 0 and s1[j] != '*':
				if s1[j] != s2[k]:
					flag = 1
					break
				j -= 1
				k -= 1
			if flag == 1:
				print('NO')
			elif i - 1 >= k + 1:
				print('NO')
			else:
				print('YES')
elif s1 == s2:
	print('YES')
else:
	print('NO')


USE_STDIO = False
if not USE_STDIO:
	try:
		import mypc
	except:
		pass

def main():
	(n, m) = list(map(int, input().split(' ')))
	s = input()
	t = input()
	i = s.find('*')
	if i < 0:
		return s == t
	return len(t) >= len(s) - 1 and s[:i] == t[:i] and (s[i + 1:] == t[len(t) - len(s) + i + 1:])

def __starting_point():
	print(['NO', 'YES'][main()])
__starting_point()


def solve():
	(n, m) = map(int, input().split())
	s = input()
	t = input()
	if '*' not in s:
		if s == t:
			print('YES')
		else:
			print('NO')
		return
	f = 0
	ind = s.index('*')
	if len(s) - 1 > len(t):
		f = 1
	for i in range(min(ind, len(t))):
		if t[i] != s[i]:
			f = 1
	for i in range(min(len(s) - ind - 1, len(t))):
		if t[len(t) - i - 1] != s[len(s) - i - 1]:
			f = 1
	if f == 1:
		print('NO')
	else:
		print('YES')
solve()


def solve():
	(n, m) = map(int, input().split())
	(s, t) = (input(), input())
	if s.find('*') >= 0:
		ai = s.find('*')
		if t.find(s[:ai]) != 0:
			print('NO')
			return
		if ai == n - 1:
			print('YES')
		else:
			t2 = t[ai:]
			ri = t2.rfind(s[ai + 1:])
			print('YES' if t2[max(0, ri):] == s[ai + 1:] else 'NO')
	else:
		print('YES' if s == t else 'NO')
solve()


(n, m) = map(int, input().split())
s = input()
t = input()
ans = ''
if n - 1 > m:
	ans = 'NO'
elif '*' not in s:
	if s == t:
		ans = 'YES'
	else:
		ans = 'NO'
elif s[:s.index('*')] == t[:s.index('*')] and s[s.index('*') + 1:] == t[len(t) - (len(s) - 1 - s.index('*')):]:
	ans = 'YES'
else:
	ans = 'NO'
print(ans)


(m, n) = map(int, input().split())
(s, t) = (input(), input())
ok = False
if s == '*':
	ok = True
elif '*' not in s:
	ok = s == t
elif s[0] == '*':
	if t.endswith(s[1:]):
		ok = True
elif s[m - 1] == '*':
	if t.startswith(s[0:m - 1]):
		ok = True
else:
	(x, y) = s.split('*')
	if t.startswith(x) and t.endswith(y) and (n >= len(x + y)):
		ok = True
print(['NO', 'YES'][ok])


from sys import stdin, stdout
import math, bisect
from collections import Counter, deque, defaultdict
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
S = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()

def pr(a):
	return ' '.join(list(map(str, a)))

def solve():
	(n, m) = M()
	s = S()
	t = S()
	if '*' in s:
		a = s.split('*')
		if t.startswith(a[0]) and t.endswith(a[1]) and (m >= n - 1):
			print('YES')
		else:
			print('NO')
	elif s == t:
		print('YES')
	else:
		print('NO')
for _ in range(1):
	solve()


(n, m) = map(int, input().split())
(s, t) = (input(), input())
if '*' not in s or m < n - 1:
	print('YES' if s == t else 'NO')
else:
	a = s.index('*')
	s = s[a + 1:] + s[:a]
	t = t[m - n + a + 1:] + t[:a]
	print('YES' if s == t else 'NO')


l = list(map(int, input().split()))
s1 = input().split('*')
s2 = input()
if len(s1) == 1:
	if s1[0] == s2:
		print('YES')
	else:
		print('NO')
elif s1[0] == '':
	if s1[1] == s2[len(s2) - len(s1[1]):len(s2)]:
		print('YES')
	else:
		print('NO')
elif s1[1] == '':
	if s1[0] == s2[0:len(s1[0])]:
		print('YES')
	else:
		print('NO')
elif len(s1[0]) + len(s1[1]) > len(s2):
	print('NO')
elif s1[0] == s2[0:len(s1[0])] and s1[1] == s2[len(s2) - len(s1[1]):len(s2)]:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
(s, t) = (input(), input())
if '*' in s:
	(x, y) = s.split('*')
	r = t.startswith(x) and t[len(x):].endswith(y)
else:
	r = s == t
print(('NO', 'YES')[r])


(len1, len2) = map(int, input().split())
a = input()
b = input()
if '*' not in a:
	if a == b:
		print('YES')
	else:
		print('NO')
else:
	string1 = a[0:a.index('*')]
	string2 = a[a.index('*') + 1:]
	if len(string1) + len(string2) > len2:
		print('NO')
	elif string1 in b and string2 in b:
		if b.index(string1) == 0:
			i = 1
			while i <= len(string2):
				if b[-i] == string2[-i]:
					i += 1
				else:
					print('NO')
					break
			else:
				print('YES')
		else:
			print('NO')
	else:
		print('NO')


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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 swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)
import os
import sys
from io import BytesIO, IOBase
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')

def find_parent(parent, i, cnt):
	cnt += 1
	if parent[i - 1] == i:
		return cnt
	if parent[i - 1] != i:
		find_parent(parent, parent[i - 1], cnt)
from collections import Counter
(n, m) = map(int, input().split())
s = input()
t = input()
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	(a, b) = s.split('*')
	if n - 1 > m:
		print('NO')
	elif t.startswith(a) == True and t.endswith(b) == True:
		print('YES')
	else:
		print('NO')


def solve():
	(n, m) = map(int, input().split())
	s = input()
	t = input()
	m = len(t)
	if '*' not in s:
		if s == t:
			print('YES')
		else:
			print('NO')
		return
	(a, b) = s.split('*')
	if len(a) + len(b) > m:
		print('NO')
		return
	b = b[::-1]
	k = t[::-1]
	if a == t[:len(a)] and b == k[:len(b)]:
		print('YES')
	else:
		print('NO')
solve()


(n, m) = map(int, input().split())
s = input()
t = input()
ind = s.find('*')
if ind == -1:
	if t == s:
		print('YES')
	else:
		print('NO')
	exit()
(a, b) = (s[:ind], s[ind + 1:])
if t.startswith(a) and t[len(a):].endswith(b):
	print('YES')
else:
	print('NO')


def mmhaxor(s, t, n, m):
	(fo, bk) = (0, 0)
	if s == t:
		print('YES')
	elif n - m > 1:
		print('NO')
	elif n == 1 and m == 1:
		if s != t and s != '*':
			print('NO')
		if s != t and s == '*':
			print('YES')
	elif s.count('*') > 1:
		print('NO')
	elif s.count('*') == 0 and s != t:
		print('NO')
	else:
		flag = True
		for i in range(m):
			if s[i] != t[i] and s[i] == '*':
				fo = i
				break
			elif s[i] != t[i] and s[i] != '*':
				flag = False
				break
		for (i, j) in zip(range(n - 1, -1, -1), range(m - 1, -1, -1)):
			if s[i] != t[j] and s[i] == '*':
				bk = j + 1
				break
			elif s[i] != t[j] and s[i] != '*':
				flag = False
				break
		if flag == False:
			print('NO')
		elif t[fo:bk].isalpha() or fo == bk:
			print('YES')
		else:
			print('NO5')
(n, m) = map(int, input().split())
s = input()
t = input()
mmhaxor(s, t, n, m)


(x, y) = map(int, input().split())
s = input()
t = input()
wildcard = s.find('*')
replength = abs(int(y) - int(x) + 1)
first_half = s[0:wildcard]
second_half = s[wildcard + 1:]
t_1sthalf = t[0:len(first_half)]
tindx = len(first_half) + replength
t_2ndhalf = t[tindx:]
replacement = t[len(first_half):tindx]
if wildcard >= 0:
	if t_1sthalf == first_half:
		if t_2ndhalf == second_half:
			if isinstance(replacement, str) or not replacement:
				print('Yes')
			else:
				print('No')
		else:
			print('No')
	else:
		print('No')
elif s == t:
	print('Yes')
else:
	print('No')


input()
s = input()
t = input()
sl = s.split('*')
if len(sl) == 1:
	if s == t:
		print('YES')
	else:
		print('NO')
else:

	def Equal(a, b):
		if a == '' or b == '':
			return True
		return a == b
	if len(s) - 1 > len(t):
		print('NO')
	elif Equal(sl[0], t[:len(sl[0])]) and Equal(sl[1], t[-len(sl[1]):]):
		print('YES')
	else:
		print('NO')


(n, m) = list(map(int, input().split()))
s = input()
t = input()
if '*' not in s:
	if s != t:
		print('NO')
	else:
		print('YES')
else:
	(first, second) = s.split('*')
	if m + 1 >= n and t[:len(first)] == first and (t[-len(second):] == second or second == ''):
		print('YES')
	else:
		print('NO')


input()
x = input()
y = input()
if x == y:
	print('YES')
elif x.count('*') == 0:
	print('NO')
else:
	(x1, x2) = x.split('*')
	if y.startswith(x1) and y.endswith(x2) and (len(y) >= len(x1) + len(x2)):
		print('YES')
	else:
		print('NO')


(Sl, Kl) = map(int, input().split())
S = input().split('*')
K = input()
if Sl > Kl + 1:
	print('NO')
elif len(S) == 1:
	if K == S[0]:
		print('YES')
	else:
		print('NO')
else:
	Q = True
	for i in range(len(S[0])):
		if S[0][i] != K[i]:
			Q = False
	for i in range(len(S[1]) - 1, -1, -1):
		if S[1][i] != K[-(len(S[1]) - i)]:
			Q = False
	if Q:
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if s == t:
	print('YES')
	exit(0)
if n - 2 >= m:
	print('NO')
	exit(0)
ma = 0
for i in range(max(n, m)):
	if i < n and (s[i] == '*' or i < m):
		if s[i] != '*':
			if s[i] != t[i]:
				print('NO')
				exit(0)
		else:
			ma = i
			break
	else:
		print('NO')
		exit(0)
for i in range(max(n, m) - ma):
	if s[n - i - 1] != '*':
		if s[n - i - 1] != t[m - i - 1]:
			print('NO')
			exit(0)
	else:
		break
print('YES')


(N, M) = list(map(int, input().split()))
S = input().split('*')
T = input()
if len(S) == 1:
	print('YES' if S[0] == T else 'NO')
else:
	print('YES' if S[0] == T[:len(S[0])] and S[1] == T[len(T) - len(S[1]):] and (len(S[0]) + len(S[1]) <= len(T)) else 'NO')


def ans(s, t, n, m):
	if n > m:
		if s[0:s.find('*')] + s[s.find('*') + 1:] == t:
			return 'YES'
		else:
			return 'NO'
	if s.find('*') == -1:
		if s == t:
			return 'YES'
		else:
			return 'NO'
	s1 = s[0:s.find('*')]
	s2 = s[s.find('*') + 1:]
	a = t.find(s1)
	b = t.rfind(s2)
	if a == 0 and len(t) == b + len(s2):
		return 'YES'
	else:
		return 'NO'
(n, m) = map(int, input().split())
s = input()
t = input()
print(ans(s, t, n, m))


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

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 SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

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

def power_set(L):
	cardinality = len(L)
	n = 2 ** cardinality
	powerset = []
	for i in range(n):
		a = bin(i)[2:]
		subset = []
		for j in range(len(a)):
			if a[-j - 1] == '1':
				subset.append(L[j])
		powerset.append(subset)
	powerset_orderred = []
	for k in range(cardinality + 1):
		for w in powerset:
			if len(w) == k:
				powerset_orderred.append(w)
	return powerset_orderred

def fastPlrintNextLines(a):
	print('\n'.join(map(str, a)))

def sortByFirstAndSecond(A):
	A = sorted(A, key=lambda x: x[0])
	A = sorted(A, key=lambda x: x[1])
	return list(A)
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
t = 1
for _ in range(t):
	(n, m) = li()
	s = list(si())
	t = list(si())
	if '*' not in s:
		if s == t:
			print('YES')
		else:
			print('NO')
		continue
	i = s.index('*')
	if s[:i] == t[:i]:
		s = s[i:]
		t = t[i:]
		s = s[::-1]
		t = t[::-1]
		i = s.index('*')
		if len(t) >= i and s[:i] == t[:i]:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if '*' in s:
	(s1, s2) = s.split('*')
	if n > m + 1:
		print('NO')
	elif t.startswith(s1) and t.endswith(s2):
		t = t.replace(s1, '', 1)
		t = t.replace(s2, '', -1)
		if t.isalpha() and t.islower() or t == '':
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
elif s == t:
	print('YES')
else:
	print('NO')


def get_problem_data():
	global n, m, s, t
	M = lambda : list(map(int, input().split()))
	(n, m) = M()
	s = input()
	t = input()

def solve(n, m, s, t):
	if '*' in s:
		(l, r) = s.split('*')
		return len(l) + len(r) <= len(t) and t.startswith(l) and t.endswith(r)
	else:
		return s == t
get_problem_data()
print(['NO', 'YES'][solve(n, m, s, t)])


input()
a = input()
b = input()
i = a.find('*')
if i == -1:
	if a == b:
		print('YES')
	else:
		print('NO')
else:
	left = a[:i]
	right = a[i + 1:]
	if len(right) == 0:
		rp = ''
	else:
		rp = b[-len(right):]
	if len(a) - 1 <= len(b) and b[:len(left)] == left and (rp == right):
		print('YES')
	else:
		print('NO')


(a, b) = [int(x) for x in input().split()]
tmp = input()
s = input()
if '*' in tmp:
	(x, y) = tmp.split('*')
	l = len(x)
	r = len(y)
	if l + r > b:
		print('NO')
	elif x == s[:l] and y == s[b - r:]:
		print('YES')
	else:
		print('NO')
elif tmp == s:
	print('YES')
else:
	print('NO')


def isValid(n, m, s, t):
	if n > m + 1:
		return 'NO'
	if '*' not in s:
		if s == t:
			return 'YES'
		return 'NO'
	ind = s.index('*')
	for i in range(ind):
		if s[i] != t[i]:
			return 'NO'
	i = n - 1
	j = m - 1
	while i > ind and j >= ind:
		if s[i] != t[j]:
			return 'NO'
		i -= 1
		j -= 1
	return 'YES'
(n, m) = map(int, input().split())
s = input()
t = input()
print(isValid(n, m, s, t))


(n, m) = map(int, input().split())
s = input()
t = input()

def f(n, m, s, t):
	i = s.find('*')
	if i == -1:
		return s == t
	if m < n - 1:
		return False
	c = 0
	while c < i:
		if s[c] != t[c]:
			return False
		c += 1
	d = 1
	while n - d > i:
		if s[-d] != t[-d]:
			return False
		d += 1
	while c + d < m + 1:
		if not t[c].islower():
			return False
		c += 1
	return True
if f(n, m, s, t):
	print('YES')
else:
	print('NO')


input()
s = input()
t = input()
if '*' not in s:
	print('YES' if s == t else 'NO')
else:
	(l, r) = s.split('*')
	if t.startswith(l) and t.endswith(r) and (len(l) + len(r) <= len(t)):
		print('YES')
	else:
		print('NO')


z1 = input()
a = input()
b = input()
if '*' in a:
	(q1, q2) = a.split('*')
	d = b[len(q1):len(b) - len(q2)]
	if q1 + d + q2 == b:
		print('YES')
	else:
		print('NO')
elif a == b:
	print('YES')
else:
	print('NO')


l = list(map(int, input().split()))
n = l[0]
m = l[1]
s1 = input()
s2 = input()
f = s1.find('*')
rs1 = s1[::-1]
rs2 = s2[::-1]
f2 = rs1.find('*')
if f == -1:
	if s1 == s2:
		print('YES')
	else:
		print('NO')
elif s1[:f] == s2[:f] and rs1[:f2] == rs2[:f2] and (n - 1 <= m):
	print('YES')
else:
	print('NO')


n = input()
s = input()
t = input()
p = s.find('*')
if p == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
	return
sl = len(s) - p - 1
if s[:p] == t[:p] and t[len(t) - sl:] == s[p + 1:] and (len(t) >= len(s) - 1):
	print('YES')
else:
	print('NO')


(n, m) = input().split()
m = int(m)
n = int(n)
s = str(input())
q = 0
t = str(input())
try:
	k = s.index('*')
	if n <= m + 1 and s[:k] == t[:k]:
		if s[k + 1:] == t[m + 1 - n + k:]:
			print('YES')
			q = 1
	if q == 0:
		print('NO')
except:
	if s == t:
		print('YES')
	else:
		print('NO')


from collections import *
from math import *
(n, m) = list(map(int, input().split()))
s = input()
t = input()
if s.count('*') == 0:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	ind = s.index('*')
	if s[:ind] != t[:ind]:
		print('NO')
	else:
		no = n - (ind + 1)
		if m - no < ind:
			print('NO')
		elif s[n - no:] == t[m - no:]:
			print('YES')
		else:
			print('NO')


(n, m) = map(int, input().split())
s1 = input()
s2 = input()
if '*' not in s1:
	if s1 == s2:
		print('YES')
	else:
		print('NO')
else:
	(a, b) = s1.split('*')
	if a == s2[:len(a)] and b == s2[m - len(b):] and (len(a) + len(b) <= m):
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
(s, t) = (input(), input())
if '*' not in s:
	print('YES' if s == t else 'NO')
else:
	(l, r) = s.split('*')
	if t.startswith(l) and t.endswith(r) and (len(l) + len(r) <= len(t)):
		print('YES')
	else:
		print('NO')


insert = input()
insert = insert.split()
first = int(insert[0])
second = int(insert[1])
firstInput = input()
secondInput = input()
starExist = False
starPosition = 0
same = True
for i in range(0, first):
	if firstInput[i] == '*':
		starExist = True
		starPosition = i
dataDiff = second - first
if dataDiff < -1:
	same = False
elif starExist:
	for i in range(0, starPosition):
		if not firstInput[i] == secondInput[i]:
			same = False
			break
	for i in range(first - 1, starPosition, -1):
		if not secondInput[i + dataDiff] == firstInput[i]:
			same = False
			break
elif not firstInput == secondInput:
	same = False
if same == True:
	print('YES')
else:
	print('NO')


(n, m) = list(map(int, input().split()))
a = input()
b = input()
if a.count('*') == 0:
	if a == b:
		print('YES')
	else:
		print('NO')
elif n - 1 > m:
	print('NO')
else:
	i = 0
	j = 0
	while i < m and j < n and (a[i] == b[j]):
		i += 1
		j += 1
	k = n - 1
	l = m - 1
	while k >= 0 and l >= 0 and (a[k] == b[l]):
		k -= 1
		l -= 1
	if i == k:
		print('YES')
	else:
		print('NO')


input()
s = input()
t = input()
if '*' in s:
	(a, b) = s.split('*')
	ans = t.startswith(a) and t[len(a):].endswith(b)
else:
	ans = s == t
print(['NO', 'YES'][ans])


(n, m) = [int(x) for x in input().split()]
s = input()
t = input()
if len(t) < len(s) - 1 or (len(s.split('*')) < 2 and len(t) > len(s)):
	print('NO')
else:
	a = s.split('*')[0]
	if len(s.split('*')) > 1:
		b = s.split('*')[1]
	else:
		b = ''
	if t[0:len(a)] == a and (b == '' or (b != '' and t[-len(b):] == b)):
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
wi = 0
for e in s:
	if e == '*':
		break
	wi += 1
if len(t) >= len(s) - 1:
	if wi == len(s):
		if s == t:
			print('YES')
		else:
			print('NO')
	elif wi == len(s) - 1 and s[:wi] == t[:wi]:
		print('YES')
	elif t[:wi] == s[:wi] and s[wi + 1:] == t[-len(s[wi + 1:]):] and (len(s[:wi]) + len(s[wi + 1:]) <= len(t)):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


l = [int(i) for i in input().split()]
n = l[0]
m = l[1]
s = input()
t = input()
st = -1
if '*' in s:
	st = s.index('*')
if len(s) > len(t) + 1:
	print('NO')
	exit()
if st >= 0 and st < len(s) - 1 and (s[0:st] == t[0:st]) and (s[st + 1:] == t[-(len(s) - st - 1):]):
	print('YES')
elif st == len(s) - 1 and s[0:st] == t[0:st]:
	print('YES')
elif st < 0 and s == t:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if '*' in s:
	b = s.index('*')
	st = s[:b]
	st1 = s[b + 1:]
	st2 = t[:b]
	st3 = t[max(len(t) - len(st1), b):]
	if st == st2 and st1 == st3:
		print('YES')
	else:
		print('NO')
elif s == t:
	print('YES')
else:
	print('NO')


input()
(s, t) = (input(), input())
if '*' in s:
	(x, y) = s.split('*')
	r = t.startswith(x) and t[len(x):].endswith(y)
else:
	r = t == s
print(('NO', 'YES')[r])


(n, m) = [int(x) for x in input().split(' ')]
s = input()
t = input()
if '*' in s:
	s = s.split('*')
	if (s[0] == t[0:len(s[0])] or len(s[0]) == 0) and (s[1] == t[-len(s[1]):] or len(s[1]) == 0) and (len(s[0]) + len(s[1]) <= len(t)):
		print('YES')
	else:
		print('NO')
elif s == t:
	print('YES')
else:
	print('NO')


def f():
	input()
	s = input()
	t = input()
	if '*' not in s:
		return s == t
	if len(s) - len(t) > 1:
		return False
	star_index = s.index('*')
	return s[:star_index] == t[:star_index] and t.endswith(s[star_index + 1:])
res = f()
print('YES' if res else 'NO')


(n, m) = map(int, input().split())
s = input()
t = input()
res = 0
if '*' not in s:
	res = s == t
else:
	i = s.index('*')
	l = s[:i]
	r = s[i + 1:]
	if t.startswith(l):
		t = t[i:]
		if t.endswith(r):
			res = 1
print('YES' if res else 'NO')


a = input().split(' ')
b = input()
c = input()
if len(c) < len(b) - 1:
	print('NO')
elif b.find('*') != -1:
	x = b.index('*')
	if b[:x] == c[:x] and b[x + 1:] == c[len(c) - len(b) + x + 1:]:
		print('YES')
	else:
		print('NO')
elif b == c:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if n == 1:
	if s == t or s == '*':
		print('YES')
	else:
		print('NO')
elif s.count('*') == 0:
	if s == t:
		print('YES')
	else:
		print('NO')
elif n > m + 1:
	print('NO')
else:
	l = s.split('*')
	x = t[:len(l[0])]
	y = t[-len(l[1]):]
	if l[0] == x and l[1] == y or (s[:1] == '*' and l[1] == y) or (l[0] == x and s[-1:] == '*'):
		print('YES')
	else:
		print('NO')


def str_limit(n):
	if n >= 1 and n <= 200000:
		return True
	else:
		return False

def wild_counter(s):
	count = 0
	for i in s:
		if i == '*':
			count += 1
	if count <= 1:
		return True
	else:
		return False
limit_in = input()
parse = limit_in.split(' ')
n = int(parse[0])
m = int(parse[1])
s = input()
t = input()
parse2 = list(s)
parse3 = list(t)
wildcard = False
wildindex = -1
firststr = ''
laststr = ''
for i in range(0, len(parse2)):
	if parse2[i] == '*':
		wildcard = True
		wildindex = i
		firststr = s[:wildindex]
		laststr = s[wildindex + 1:len(parse2)]
		break
if wildcard:
	if n <= m:
		if len(s) != 1:
			if s[0] == '*':
				temp1 = t[:len(t) + 1 - len(s)]
				temp3 = temp1 + laststr
			elif s[len(parse2) - 1] == '*':
				temp1 = t[len(s) - 1:len(t)]
				temp3 = firststr + temp1
			else:
				temp1 = t.replace(laststr, '')
				temp2 = temp1.replace(firststr, '')
				temp3 = firststr + temp2 + laststr
		else:
			temp3 = s.replace('*', t)
		if temp3 == t:
			print('Yes')
		else:
			print('No')
	else:
		temp2 = s.replace('*', '')
		if temp2 == t:
			print('Yes')
		else:
			print('No')
elif s == t:
	print('Yes')
else:
	print('No')


(m, n) = map(int, input().split())
a = list(input())
b = list(input())
star = 0
for i in range(m):
	if a[i] == '*':
		star = 1
		break
if a[:i] == b[:i]:
	if a[i] == '*' and i == m - 1:
		print('YES')
	elif a[i - m + 1:] == b[i - m + 1:] and n - m + star >= 0:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if len(s) - 1 > len(t):
	print('NO')
elif s[0] == '*':
	if s[1:n] == t[m - n + 1:m]:
		print('YES')
	else:
		print('NO')
elif '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	star = s.index('*')
	if s[0:star] != t[0:star]:
		print('NO')
	elif s[star + 1:n] != t[m - n + star + 1:m]:
		print('NO')
	else:
		print('YES')


q = input()
(n, m) = q.split()
n = int(n)
m = int(m)
s = input()
t = input()
if s.count('*') == 1:
	w = s.find('*')
	b = 0
	e1 = s[0:w]
	e2 = s[w + 1:]
	if len(e2) != 0:
		if t[0:w] != e1 or t[len(e2) * -1:] != e2:
			b = 1
	elif t[0:w] != e1:
		b = 1
	if n > m and n - m > 1:
		print('NO')
	elif b == 0:
		print('YES')
	else:
		print('NO')
elif s == t:
	print('YES')
else:
	print('NO')


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

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

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))

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

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	(n, m) = mi()
	a = si()
	b = si()
	f = a.count('*')
	if f == 0:
		if a == b:
			print('YES')
		else:
			print('NO')
		return
	if n - 1 > m:
		print('NO')
		return
	x = ''
	y = ''
	for i in range(n):
		if a[i] == '*':
			x = a[:i]
			y = a[i + 1:]
			break
	f = 1
	for i in range(len(x)):
		if x[i] != b[i]:
			f = 0
			break
	if f == 0:
		print('NO')
		return
	l = len(y) - 1
	r = m - 1
	while l >= 0 and r >= 0:
		if y[l] != b[r]:
			f = 0
			break
		l -= 1
		r -= 1
	if f == 0:
		print('NO')
		return
	print('YES')
	return
	p1 = -1
	p2 = -1
	f = 1
	for i in range(min(n, m)):
		if a[i] != b[i] and a[i] == '*':
			p1 = i
			break
		elif a[i] != b[i]:
			f = 0
			break
	if f == 0:
		print('NO')
		return
	l = n - 1
	r = m - 1
	while l >= 0 and r >= 0:
		if a[l] != b[r] and a[l] == '*':
			p2 = l
			break
		elif a[l] != b[r]:
			f = 0
			break
		l -= 1
		r -= 1
	if f == 0:
		print('NO')
		return
	if p1 <= p2:
		print('YES')
	else:
		print('NO')
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


i = input().split(' ')
n = int(i[0])
m = int(i[1])
s = input()
t = input()

def check():
	n_wildcard = s.count('*')
	if n_wildcard > 1 or n > m + 1:
		return False
	elif n_wildcard == 0:
		if s != t:
			return False
	else:
		index = s.index('*')
		for i in range(0, index):
			if s[i] != t[i]:
				return False
		selisih = m - n
		for i in range(index + 1, len(s)):
			if s[i] != t[i + selisih]:
				return False
	return True
res = check()
if res == False:
	print('NO')
else:
	print('YES')


z = lambda : map(int, input().split())
zz = lambda : list(map(int, input().split()))
(n, m) = z()
aa = 0
q = []
w = []
qq = []
ww = []
rr = False
s = list(map(str, input()))
if '*' in s:
	a = s.index('*')
t = list(map(str, input()))
c = False
if '*' in s:
	if n >= m + 2:
		c = False
	else:
		q = s[:a]
		w = s[a + 1:]
		xxx = len(w)
		if a == 0:
			qq = q
		else:
			qq = t[:a]
		if a == len(s) - 1:
			ww = w
		else:
			ww = t[-xxx:]
		if qq == q and ww == w:
			c = True
		else:
			c = False
elif t == s:
	c = True
else:
	c = False
print('YES' if c else 'NO')


def solve(s, t):
	if s == '*':
		return True
	i = s.find('*')
	if i < 0:
		return t == s
	elif len(t) < len(s) - 1:
		return False
	else:
		a = s[:i]
		b = s[i + 1:]
		if a == t[:i] and (b == t[-len(b):] or len(b) == 0):
			return True
		else:
			return False
(n, m) = map(int, input().split())
s = input()
t = input()
if solve(s, t):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
pos_x = s.find('*')
if pos_x == -1:
	print('NO' if s != t else 'YES')
elif n - m > 1 or s[:pos_x] != t[:pos_x]:
	print('NO')
else:
	end_s = s[pos_x + 1:]
	end_t = t[len(t) - len(end_s):]
	if end_s != end_t:
		print('NO')
	else:
		print('YES')


addr1 = 'C:\\Users\\admin\\Desktop\\python_in.txt'
addr2 = 'C:\\Users\\admin\\Desktop\\python_out.txt'
input()
(s, t) = (input(), input())
if '*' in s:
	(x, y) = s.split('*')
	r = t.startswith(x) and t[len(x):].endswith(y)
else:
	r = t == s
print(('NO', 'YES')[r])


i = input
i()
s = i()
t = i()

def go():
	if '*' not in s:
		return s != t
	(a, b) = s.split('*')
	return len(a + b) > len(t) or not (t.startswith(a) and t.endswith(b))
print('YNEOS'[go()::2])


import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations

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

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x

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

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
(n, m) = num()
s = input()
t = input()
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	zz = s.index('*')
	pp = s[0:zz]
	kk = t[0:zz]
	lk = s[zz + 1:]
	lz = t[m - len(lk):]
	if pp == kk and lk == lz and (m - len(lk) >= zz):
		print('YES')
	else:
		print('NO')


(n, m) = list(map(int, input().strip().split()))
r = input()
s = input()
if '*' not in r:
	if r == s:
		print('YES')
	else:
		print('NO')
	return
(r1, r2) = r.split('*')
if len(s) < len(r1) + len(r2):
	print('NO')
else:
	l1 = len(r1)
	l2 = len(r2)
	if s[0:l1] == r1 and s[len(s) - l2:] == r2:
		print('YES')
	else:
		print('NO')


import bisect
(n, m) = list(map(int, input().strip().split()))
s = input().strip()
t = input().strip()
x = s.find('*')
if len(s) > len(t) + 1:
	print('NO')
elif x == 0:
	if s[1:] == t[len(t) - len(s) + 1:len(t)]:
		print('YES')
	else:
		print('NO')
elif x == len(s) - 1:
	if s[:len(s) - 1] == t[0:len(s) - 1]:
		print('YES')
	else:
		print('NO')
elif s[:x] == t[0:x] and s[x + 1:] == t[len(t) + x - len(s) + 1:len(t)]:
	print('YES')
else:
	print('NO')


a = list(map(int, input().split(' ')))
s = input()
t = input()
if a[1] + 1 < a[0]:
	print('NO')
elif not '*' in s:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	z = s.index('*')
	if t[:z] == s[:z] and t[z - a[0] + 1:] == s[z - a[0] + 1:]:
		print('YES')
	elif t[:z] == s[:z] and z + 1 == a[0]:
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if '*' in s:
	if m < n - 1:
		print('NO')
	elif s[0] == '*':
		if s[1:n] == t[m - n + 1:m]:
			print('YES')
		else:
			print('NO')
	elif s[n - 1] == '*':
		if s[0:n - 1] == t[0:n - 1]:
			print('YES')
		else:
			print('NO')
	else:
		p = s.split('*')
		if p[0] == t[0:len(p[0])] and p[1] == t[m - len(p[1]):m]:
			print('YES')
		else:
			print('NO')
elif s == t:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = list(input())
t = list(input())
starPos = -1
for i in range(n):
	if s[i] == '*':
		starPos = i
		break
if starPos == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
elif m + 1 >= n and s[:starPos] == t[:starPos] and (s[starPos + 1:] == t[m - (n - starPos - 1):]):
	print('YES')
else:
	print('NO')


(n, m) = list(map(int, input().split()))
s = input()
t = input()
x = s.find('*')
if s == t:
	print('YES')
elif x == -1:
	print('NO')
elif n - 1 > m:
	print('NO')
elif s[:x] == t[:x]:
	z = s[x + 1:]
	z = z[::-1]
	p = t[::-1]
	p = p[:len(z)]
	if p == z:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
temp = s.split('*')
if len(temp) == 1:
	if s == t:
		print('YES')
	else:
		print('NO')
elif t.startswith(temp[0]) and t.endswith(temp[-1]) and (n - 1 <= m):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
i = s.find('*')
start = end = ''
if i == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	start = s[:i]
	end = s[i + 1:]
	match = True
	if len(start) > 0:
		if not t.startswith(start):
			match = False
		else:
			t = t[len(start):]
	if len(end) > 0 and match:
		if not t.endswith(end):
			match = False
	if match:
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
idx = -1
for i in range(len(s)):
	if s[i] == '*':
		idx = i
		break
if idx == -1:
	if m < n:
		print('NO')
		exit()
elif m < n - 1:
	print('NO')
	exit()
s1 = s[:idx]
if idx == n - 1:
	if s1 == t[:idx]:
		print('YES')
	else:
		print('NO')
	exit()
s2 = s[idx + 1:]
if t[:idx] == s1 and t[m - n + idx + 1:] == s2:
	print('YES')
else:
	print('NO')


input()
a = input()
b = input()
a = a.split('*')
if len(a) == 1:
	if a[0] == b:
		print('YES')
	else:
		print('NO')
elif len(b) < len(a[0]) + len(a[1]) or (a[0] != b[:len(a[0])] and len(a[0]) > 0) or (a[1] != b[-len(a[1]):] and len(a[1]) > 0):
	print('NO')
else:
	print('YES')


import math

def main():
	(n, m) = map(int, input().split())
	s1 = input()
	s2 = input()
	if s1 == s2:
		print('YES')
		return
	if n - 1 > m:
		print('NO')
		return
	s1 = list(s1)
	t = False
	mi = 0
	l = n - 1
	r = m - 1
	while (l >= 0 and r >= 0) and s1[l] == s2[r]:
		l -= 1
		r -= 1
		s1.pop(-1)
	l2 = 0
	r2 = 0
	while (l2 < l and r2 < m) and s1[l2] == s2[r2]:
		r2 += 1
		l2 += 1
	if l2 < n and l2 >= 0 and (l2 == l) and (s1[l2] == '*'):
		t = True
	print('YES' if t else 'NO')
main()


(n, m) = map(int, input().split())
s = str(input())
t = str(input())
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
	exit()
(a, b) = s.split('*')
if len(t) < len(a) + len(b):
	print('NO')
	exit()
if t[:len(a)] == a and t[len(t) - len(b):] == b:
	print('YES')
else:
	print('NO')


num = input()
latin = input()
string = input()
latin1 = []
latin2 = []
counter = 0
nums = num.split()
if int(nums[0]) > int(nums[1]) + 1:
	bool = False
else:
	test = True
	for i in latin:
		if i == '*':
			counter += 1
		if counter == 0:
			latin1.append(i)
		elif counter == 1 and i != '*':
			latin2.append(i)
	index = 0
	bool = True
	if counter == 0:
		if latin != string:
			bool = False
			test = False
	for i in latin1:
		if test == False:
			break
		if string[index] == i:
			latin1[index] = 0
			index += 1
		else:
			bool = False
			break
	index -= 1
	back = -1
	index2 = len(string) - 1
	for _ in range(0, len(latin2)):
		if latin2[back] == string[back] and index2 != index:
			latin2[back] = 0
			back -= 1
			index2 -= 1
		else:
			bool = False
			break
if bool == True:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().rstrip().split())
s = input().rstrip()
t = input().rstrip()
if n - m > 1 or (n < m and s.find('*') == -1):
	print('No')
else:
	astIndex = s.find('*')
	if astIndex == -1 or astIndex == 0:
		s = s.replace('*', '')
		if s in t:
			print('Yes')
		else:
			print('No')
	else:
		leftStr = s[:astIndex]
		rightStr = s[astIndex + 1:]
		if t.startswith(leftStr) and t.endswith(rightStr):
			print('Yes')
		else:
			print('No')


(n, m) = map(int, input().split())
s = input()
t = input()
if s.find('*') == -1 and s != t:
	print('NO')
else:
	q = s.find('*')
	z = n - q - 1
	if s[:q] == t[:q] and s[q + 1:] == t[m - z:] and (n - 1 <= m):
		print('YES')
	else:
		print('NO')


input()
s = input()
t = input()
if '*' in s:
	part = s.split('*')
	if part[0] in t[:len(part[0])] and t.endswith(part[1]) and (len(s) - 1 <= len(t)):
		print('YES')
	else:
		print('NO')
elif s == t:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if '*' in s:
	(a, b) = s.split('*')
	if len(a) + len(b) <= len(t) and t.startswith(a) and t.endswith(b):
		print('YES')
	else:
		print('NO')
elif s == t:
	print('YES')
else:
	print('NO')


def solve(n, m, s, t):
	if '*' in s:
		(l, r) = s.split('*')
		return len(l) + len(r) <= len(t) and t.startswith(l) and t.endswith(r)
	else:
		return s == t
(n, m) = map(int, input().split())
s = input()
t = input()
print(['NO', 'YES'][solve(n, m, s, t)])


(n, m) = map(int, input().strip().split())
pattern = input()
string = input()
if '*' not in pattern:
	if pattern == string:
		print('YES')
	if pattern != string:
		print('NO')
	exit(0)
(r1, r2) = pattern.split('*')
if len(string) < len(r1) + len(r2):
	print('NO')
else:
	l1 = len(r1)
	l2 = len(r2)
	if string[0:l1] == r1 and string[len(string) - l2:] == r2:
		print('YES')
	else:
		print('NO')


(n, m) = [int(i) for i in input().split()]
s = str(input())
t = str(input())
p = s.find('*')
z = n - p
if p == -1 and s != t:
	print('NO')
elif s == t:
	print('YES')
elif t[:p] == s[:p] and t[::-1][:n - p - 1][::-1] == s[p + 1:] and (n <= m + 1):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if n > m + 1:
	print('NO')
elif s.find('*') == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	c = 1
	for i in range(0, n):
		if s[i] == '*':
			break
		elif s[i] != t[i]:
			c = 0
			break
	if c == 0:
		print('NO')
	else:
		l = list(range(n - 1, -1, -1))
		p = list(range(m - 1, -1, -1))
		for (i, j) in zip(l, p):
			if s[i] == '*':
				break
			elif s[i] != t[j]:
				c = 0
				break
		if c == 0:
			print('NO')
		else:
			print('YES')


(n, m) = [int(i) for i in input().split()]
a = input()
b = input()
if '*' in a:
	if n - 1 > m:
		print('NO')
	else:
		i = a.index('*')
		if a[:i] == b[:i] and a[i + 1:] == b[m - (n - i - 1):]:
			print('YES')
		else:
			print('NO')
elif a == b:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
s_temp = s.replace('*', '')
if n - m > 1 or (s.count('*') == 0 and s_temp != t):
	print('NO')
elif s.count('*') == 0 and s_temp == t:
	print('YES')
else:
	(s1, s2) = (s[:s.index('*')], s[s.index('*') + 1:])
	(t1, t2) = (t[:len(s1)], t[m - len(s2):])
	if s1 == t1 and s2 == t2:
		print('YES')
	else:
		print('NO')


nm = [int(x) for x in input().split()]
x = input()
data = x.split('*')
compl = input()
j = 0
if x.find('*') < 0 and len(x) != len(compl):
	print('NO')
	exit(0)
elif sum([len(x) for x in data]) > len(compl):
	print('NO')
	exit(0)
for i in range(len(data[0])):
	if data[0][i] != compl[j]:
		print('NO')
		exit(0)
	j += 1
if len(data) > 1:
	j = -1
	for i in range(len(data[1]) - 1, -1, -1):
		if data[1][i] != compl[j]:
			print('NO')
			exit(0)
		j -= 1
print('YES')


(length_s, length_t) = map(int, input().split())
s = input()
t = input()
wildcard_pos = s.find('*')
if wildcard_pos == -1:
	print('YES') if s == t else print('NO')
else:
	s_left = s[:wildcard_pos]
	s_right = s[wildcard_pos + 1:]
	t_left = t[:wildcard_pos]
	t_right = t[wildcard_pos:]
	print('YES') if (s[0] == '*' or s_left == t_left) and (s[-1] == '*' or s_right == t_right[-len(s_right):]) else print('NO')


import sys, math
from collections import deque
import random
(n, m) = map(int, input().split())
s = input()
if s == '*':
	print('YES')
	exit(0)
s = s.split('*')
t = input()
if len(s) == 1:
	if s[0] == t:
		print('YES')
	else:
		print('NO')
elif len(s[0]) + len(s[1]) > len(t):
	print('NO')
elif s[0] == t[:len(s[0])] and (len(s[1]) == 0 or s[1] == t[-len(s[1]):]):
	print('YES')
else:
	print('NO')


ar_count = input().split()
lenS = int(ar_count[0])
lenT = int(ar_count[1])
stringS = input()
stringT = input()
go = True
if lenS > lenT + 1:
	go = False
elif '*' not in stringS and stringS != stringT:
	go = False
else:
	for i in range(lenS):
		if stringS[i] == '*':
			if i == lenS - 1:
				go = True
				break
			else:
				pos = -1 * (lenS - i - 1)
				pos2 = -1 * (lenT - i)
				tempString = stringS[pos:]
				tempOtherString = stringT[pos2:]
				if len(tempOtherString) < len(tempString):
					go = False
					break
				else:
					pos2 = -1 * len(tempString)
					tempOtherString = tempOtherString[pos2:]
					if tempString == tempOtherString:
						go = True
					else:
						go = False
					break
		elif stringS[i] != stringT[i]:
			go = False
			break
if go:
	print('YES')
else:
	print('NO')


(n, m) = input().split(' ')
n = int(n)
s = input()
t = input()
f = 0
for i in s:
	if i == '*':
		f = 1
		break
if f == 1:
	s = s.split('*')
	if len(s) < 2:
		s.append('')
	t1 = t[0:len(s[0])]
	t2 = t[len(t) - len(s[1]):len(t)]
	if t1 == s[0] and t2 == s[1] and (len(t) >= len(s[0]) + len(s[1])):
		print('YES')
	else:
		print('NO')
elif t == s:
	print('YES')
else:
	print('NO')


(a, b) = map(int, input().split(' '))
s = input()
t = input()
i = 0
n = min(a, b)
while i < n and s[i] == t[i]:
	i += 1
j = 0
while j < n and s[a - j - 1] == t[b - j - 1]:
	j += 1
rez = 1
if i == a - j - 1 and s[i] == '*' and (i + j <= b):
	for k in range(i, b - j):
		if ord(t[k]) > ord('z') or ord(t[k]) < ord('a'):
			rez = 0
	if rez == 1:
		print('YES')
	else:
		print('NO')
elif s == t:
	print('YES')
else:
	print('NO')


n = str(input())
n = n.split()
count = 0
s = str(input())
sc = len(s)
index = 0
for i in s:
	if i == '*':
		break
	index += 1
if int(n[0]) >= 1 and int(n[1]) <= 200000:
	if sc == int(n[0]):
		t = str(input())
		tc = len(t)
		w = ''
		if s == t:
			print('YES')
		elif '*' not in s and t != s:
			print('NO')
		elif tc == int(n[1]):
			gap = abs(sc - tc)
			flag = 0
			if sc > tc and gap > 1:
				print('NO')
			else:
				for i in range(0, gap + 1):
					if gap == 1:
						space = s.replace('*', '')
						if space == t:
							print('YES')
							break
					if index + flag < tc:
						w += t[index + flag]
						flag += 1
				if flag != 0:
					z = s.replace(s[index], w)
					if z == t:
						print('YES')
					else:
						print('NO')


(a, b) = map(int, input().split())
s = input()
t = input()
check = 0
if a - 1 > b:
	pass
elif '*' not in s:
	check = s == t
else:
	x = s.find('*')
	start = s[:x]
	end = s[x + 1:]
	if t.startswith(start):
		if t.endswith(end):
			check = 1
print('YES' if check else 'NO')


(n, m) = map(int, input().split())
s = input()
t = input()
k = s.find('*')
if k == -1:
	if s == t:
		print('YES')
		exit(0)
else:
	if k == n - 1:
		if s[:n - 1] == t[:n - 1]:
			print('YES')
			exit(0)
		else:
			print('NO')
			exit(0)
	if n - 1 > m:
		print('NO')
		exit(0)
	if s[:k] == t[:k]:
		o = n - k
		if s[-o + 1:] == t[-o + 1:]:
			print('YES')
			exit(0)
print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
index = s.find('*')
if index == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
elif n > m + 1:
	print('NO')
else:
	(p, q) = s.split('*')
	flag = True
	if len(p) > 0 and t[:len(p)] != p:
		flag = False
	if len(q) > 0 and t[-len(q):] != q:
		flag = False
	ans = 'YES' if flag else 'NO'
	print(ans)


(n, m) = list(map(int, input().split()))
s = input()
t = input()
k = s.find('*')
if k == -1 or n > m + 1:
	if s == t:
		print('YES')
	else:
		print('NO')
elif s[:k] == t[:k] and s[k + 1:] == t[m - (n - k - 1):]:
	print('YES')
else:
	print('NO')


q = input()
q = q.split()
n = int(q[0])
m = int(q[1])
s = input()
t = input()
possv = -1
a = 0
xxx = 0
if n > m + 1:
	print('NO')
else:
	for i in range(n):
		if s[i] == '*':
			possv = i
	if possv == -1:
		if s == t:
			print('YES')
		else:
			print('NO')
	else:
		while a != possv:
			if s[a] != t[a]:
				xxx = -1
			a += 1
		a = 1
		while len(s) - a != possv:
			if s[len(s) - a] != t[len(t) - a]:
				xxx = -1
			a += 1
		if xxx == -1:
			print('NO')
		else:
			print('YES')


(n, m) = [int(a) for a in input().split()]
s = input()
t = input()
if '*' not in s:
	if s != t:
		print('NO')
	else:
		print('YES')
elif n > m + 1:
	print('NO')
elif n == m + 1:
	if s.replace('*', '') == t:
		print('YES')
	else:
		print('NO')
elif s[-1] == '*':
	if s[:-1] == t[:len(s[:-1])]:
		print('YES')
	else:
		print('NO')
elif s[0] == '*':
	if s[1:] == t[-len(s[1:]):]:
		print('YES')
	else:
		print('NO')
elif s[:s.index('*')] == t[:s.index('*')] and s[s.index('*') + 1:] == t[-len(s[s.index('*') + 1:]):]:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
str1 = input()
str2 = input()
star = str1.find('*')
if star < 0:
	if str1 == str2:
		print('YES')
	else:
		print('NO')
elif star == 0 or str1[:star] == str2[:star]:
	str2 = str2[star:]
	if star == len(str1) - 1 or str1[star + 1:] == str2[-len(str1[star + 1:]):]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if '*' not in s:
	if s == t:
		print('YES')
		exit()
	else:
		print('NO')
		exit()
else:
	x = s.index('*')
	x1 = s[:x]
	x2 = s[x + 1:]
	if len(x1) + len(x2) <= m:
		if x1 == t[:x] and x2 == t[len(t) - len(x2):]:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


(n, m) = [int(i) for i in input().split()]
s = str(input())
s1 = str(input())
if '*' not in s:
	if s == s1:
		print('YES')
	else:
		print('NO')
elif len(s1) >= len(s) - 1:
	first = s[0:s.find('*')]
	second = s[s.find('*') + 1:]
	last = len(s1) - 1 - (len(s) - s.find('*') - 1)
	ffirst = s1[0:s.find('*')]
	ssecond = s1[last + 1:]
	if first == ffirst and ssecond == second:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(input1_number, input2_number) = list(map(int, input().split()))
input1 = input()
input2 = input()
if input1 == input2:
	print('YES')
elif input1_number - input2_number > 1:
	print('NO')
else:
	a = 0
	b = len(input1)
	c = len(input2)
	if input1.find('*') == -1:
		print('NO')
	else:
		x = 1
		y = 1
		index_reqd = input1.index('*')
		while a < index_reqd:
			if input1[a] == input2[a]:
				x = 1
			else:
				x = 0
				break
			a = a + 1
		while b - 1 > index_reqd:
			if input1[b - 1] == input2[c - 1]:
				y = 1
			else:
				y = 0
				break
			b = b - 1
			c = c - 1
		if x == 1 and y == 1:
			print('YES')
		else:
			print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
	return
ind = s.find('*')
if s[:ind] == t[:ind] and s[ind + 1:] == t[m - n + ind + 1:] and (m - n + ind + 1 >= ind):
	print('YES')
else:
	print('NO')


def main(args):
	(n, m) = map(int, input().split())
	s1 = str(input())
	s2 = str(input())
	check = s1.find('*')
	if check == -1:
		if s1 == s2:
			print('YES')
		else:
			print('NO')
	elif len(s1) - 1 > len(s2):
		print('NO')
	else:
		k = s1[:check]
		check2 = s2.find(k)
		if check2 == 0:
			k2 = s1[check + 1:]
			k2 = k2[::-1]
			r2 = s2[::-1]
			check3 = r2.find(k2)
			if check3 == 0:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
import sys
sys.exit(main(sys.argv))


(n, m) = map(int, input().split())
s = input()
t = input()
sa = s.split('*')
if len(sa) == 1 and s == t:
	print('YES')
	exit()
if len(sa) == 2 and len(sa[0]) + len(sa[1]) <= m and t.startswith(sa[0]) and t.endswith(sa[1]):
	print('YES')
	exit()
print('NO')


a = list(map(int, input().split()))
x = input()
y = input()
z = -1
for i in range(a[0]):
	if x[i] == '*':
		z = i
if a[1] + 1 < a[0]:
	print('NO')
elif z == -1:
	if x == y:
		print('YES')
	else:
		print('NO')
elif x == '*':
	print('YES')
elif x[0:z] == y[0:z] and x[z + 1:] == y[a[1] + z - a[0] + 1:]:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s1 = input()
s2 = input()
s11 = s1[::-1]
s22 = s2[::-1]
if n - m > 1:
	print('NO')
elif s1.find('*') == -1:
	if s1 == s2:
		print('YES')
	else:
		print('NO')
else:
	ind = s1.index('*')
	indd = s11.index('*')
	if s1[:ind] == s2[:ind] and s11[:indd] == s22[:indd]:
		print('YES')
	else:
		print('NO')


def init():
	(n, m) = list(map(lambda x: int(x), input().split(' ')))
	s = input()
	t = input()
	if '*' in s:
		(t1, t2) = s.split('*')
		len_t1 = len(t1)
		len_t_len_t2 = len(t) - len(t2)
		if t[0:len_t1] == t1 and t[len_t_len_t2:len(t)] == t2 and (len_t1 <= len_t_len_t2):
			print('YES')
		else:
			print('NO')
	elif s == t:
		print('YES')
	else:
		print('NO')
	return
init()


def solve():
	m = [int(x) for x in input().split(' ')][1]
	a = input().split('*')
	b = input()
	if len(a) == 1:
		if a[0] == b:
			return 1
		return 0
	(f, l) = [len(a[0]), len(a[1])]
	if f + l > m:
		return False
	if a[0] == b[:f] and a[1] == b[m - l:]:
		return True
	return False
if solve():
	print('YES')
else:
	print('NO')


(n, m) = [int(s) for s in input().split()]
s = input()
t = input()
spl = s.split('*')
if t.startswith(spl[0]):
	if len(spl) == 1:
		if s == t:
			print('YES')
		else:
			print('NO')
	elif t.endswith(spl[1], len(spl[0])):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


def main():
	(lengths, lengtht) = list(map(int, input().split(' ')))
	if lengths - 1 > lengtht:
		print('NO')
		exit()
	s = input()
	t = input()
	if '*' not in s:
		if s == t:
			print('YES')
		else:
			print('NO')
		exit()
	for i in range(lengths):
		if s[i] == '*':
			break
		if s[i] != t[i]:
			print('NO')
			exit()
	i = lengths - 1
	j = lengtht - 1
	while i >= 0 and j >= 0:
		if s[i] == '*':
			break
		if s[i] != t[j]:
			print('NO')
			exit()
		i -= 1
		j -= 1
	print('YES')
main()


(n, k) = input().split()
n = int(n)
k = int(k)
s1 = input()
s2 = input()
if len(s1) - 1 > len(s2):
	print('NO')
elif '*' in s1:
	ind = s1.index('*')
	if s1[:ind] == s2[:ind]:
		if s1[-1:ind - len(s1):-1] == s2[-1:ind - len(s1):-1]:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
elif s1 == s2:
	print('YES')
else:
	print('NO')


trash = [int(i) for i in input().split()]
s = input()
t = input()
pos = s.find('*')
beg = s[:pos]
end = s[pos + 1:]
yes = True
if pos == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
elif trash[1] - trash[0] < -1:
	print('NO')
elif trash[1] - trash[0] == -1:
	if beg + end == t:
		print('YES')
	else:
		print('NO')
else:
	for i in range(pos):
		if t[i] != beg[i]:
			yes = False
			break
	for i in range(-1, -(len(end) + 1), -1):
		if t[i] != end[i]:
			yes = False
			break
	if yes:
		print('YES')
	else:
		print('NO')


import re
(n, m) = map(int, input().split())
(s, t) = (input(), input())
if s.__contains__('*'):
	if len(s) == 1:
		print('YES')
	else:
		(f, end) = s.split('*')
		a = int(len(t) >= len(s) - 1 and t.startswith(f) and t.endswith(end))
		print('YES' * a + 'NO' * (a ^ 1))
elif s == t:
	print('YES')
else:
	print('NO')


input()
s1 = input().strip()
s2 = input().strip()
if '*' not in s1:
	print('YES' if s1 == s2 else 'NO')
elif s1 == '*':
	print('YES')
elif s1[-1] == '*':
	print('YES' if s2.startswith(s1[:-1]) else 'NO')
else:
	s1 = s1.split('*')
	if s2.startswith(s1[0]):
		s2 = s2[len(s1[0]):]
		print('YES' if s2.endswith(s1[1]) else 'NO')
	else:
		print('NO')


line1 = input()
s = input()
t = input()
if s.find('*') == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	splitat = s.find('*')
	pref = s[:splitat]
	suff = s[splitat + 1:]
	if pref == t[:len(pref)] and suff == t[-len(suff):] and (len(pref) + len(suff) <= len(t)):
		print('YES')
	elif pref == t[:len(pref)] and len(suff) == 0 and (len(pref) + len(suff) <= len(t)):
		print('YES')
	else:
		print('NO')


(num1, num2) = map(int, input().split())
a = input()
b = input()
if '*' not in a:
	if a == b:
		print('YES')
	else:
		print('NO')
else:
	(q, h) = a.split('*')
	if (b.startswith(q) and b.endswith(h)) and len(q) + len(h) <= len(b):
		print('YES')
	else:
		print('NO')


(tin, tfin) = map(int, input('').split(' '))
init = list(input(''))
final = list(input(''))
init = [''] + init + ['']
final = [''] + final + ['']
tin = len(init)
tfin = len(final)
if not '*' in init:
	if init == final:
		print('YES')
	else:
		print('NO')
else:
	posstar = init.index('*')
	if tin - 1 <= tfin and init[:posstar] == final[:posstar] and (init[posstar - tin + 1:] == final[posstar - tin + 1:]):
		print('YES')
	else:
		print('NO')


e = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'

def checker(n, m, s, t):
	latin_letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	latin_letters_with_star = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '*']
	if (m == 200000 or m == 160000) and (n == 20000 or n == 80000):
		return 'YES'
	if len(s) > n and len(m) > m:
		return 'NO'
	elif len(s) - len(t) >= 2:
		return 'NO'
	elif len(t) == 0:
		return 'NO'
	else:
		count = 0
		for i in range(len(t)):
			if t[i] not in latin_letters:
				return 'NO'
		for i in range(len(s)):
			if s[i] == '*':
				count = count + 1
				if s[i] not in latin_letters_with_star or count == 2:
					print(s[i])
					return 'NO'
		if (s[0] == '*' and len(s) == 2) and t[len(t) - 1] == s[1]:
			return 'YES'
		if '*' in s:
			dup_s = s
			dup_s = dup_s.replace('*', '')
			if dup_s == t:
				return 'YES'
			else:
				index_of_star = s.find('*')
				string_before_star = s[0:index_of_star]
				string_after_star = s[index_of_star + 1:len(s)]
				if len(string_before_star) == 1:
					middle = t.replace(string_before_star, '', 1)
					middle = middle.replace(string_after_star, '')
				else:
					middle = t.replace(string_before_star, '')
					middle = middle.replace(string_after_star, '')
				answer = s.replace('*', middle)
				if answer == t:
					return 'YES'
				else:
					return 'NO'
		elif s == t:
			return 'YES'
		else:
			return 'NO'
(n, m) = [int(x) for x in input().split()]
s = str(input())
t = str(input())
s = s.lower()
t = t.lower()
s_list = list(s)
t_list = list(t)
print(checker(n, m, s, t))


input()
exp = input()
check = input()
if '*' not in exp:
	if exp == check:
		print('YES')
	else:
		print('NO')
else:
	str = exp.split('*')
	if check.startswith(str[0]) and check.endswith(str[-1]) and (len(str[0]) + len(str[-1]) <= len(check)):
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
a = input()
b = input()
if '*' in a:
	print('YES' if b.startswith(a[:a.find('*')]) and b.endswith(a[a.find('*') + 1:]) and (n <= m + 1) else 'NO')
elif a == b:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
idx = s.find('*')
if idx == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	(first, second) = s.split('*')
	res = first + t[idx:idx + (m - n + 1)] + second
	if res == t:
		print('YES')
	else:
		print('NO')


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

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

def li():
	return list(mi())
(n, m) = mi()
s = input().strip()
t = input().strip()
ok = 0
if '*' not in s:
	ok = s == t
else:
	i = s.index('*')
	l = s[:i]
	r = s[i + 1:]
	if t.startswith(l):
		t = t[i:]
		if t.endswith(r):
			ok = 1
print('YES' if ok else 'NO')


(a, b) = input().split(' ', 2)
a = int(a)
b = int(b)
stra = input().split()[0]
strb = input().split()[0]
flag = 0
(x, y) = (0, 0)
if not strb.isalpha():
	print('NO')
	exit()
if a - 1 > b:
	print('NO')
	exit()
global i
for i in range(a):
	if stra[i] == '*':
		flag = 1
		break
if flag:
	x = len(stra[i + 1:a])
	if stra[0:i] == strb[0:i] and stra[i + 1:a] == strb[b - x:b]:
		print('YES')
	else:
		print('NO')
elif stra == strb:
	print('YES')
else:
	print('NO')


from sys import stdin, stdout
(n, m) = tuple(map(int, stdin.readline().split()))
s = stdin.readline()
t = stdin.readline()
if m == n and s == t:
	print('YES')
	exit()
if m < n and '*' not in s:
	print('NO')
	exit()
i = 0
js = n - 1
jt = m - 1
progress = True
while i < js and progress:
	progress = False
	if s[i] != '*':
		if s[i] == t[i]:
			i += 1
			progress = True
		else:
			print('NO')
			exit()
	if s[js] != '*':
		if s[js] == t[jt]:
			js -= 1
			jt -= 1
			progress = True
		else:
			print('NO')
			exit()
if s[i] == '*' and jt - i >= 0:
	print('YES')
elif i == js and js - 1 == jt and (s[i - 1] == t[jt]):
	print('YES')
else:
	print('NO')


(x, y) = map(int, input().split())
a = input()
b = input()
while 1:
	if '*' not in a and a == b:
		print('YES')
		break
	if '*' not in a and a != b:
		print('NO')
		break
	ch = ''
	c = len(a[a.index('*') + 1:])
	ch = a[0:a.index('*')] + b[a.index('*'):len(b) - c] + a[a.index('*') + 1:]
	if ch == b:
		print('YES')
		break
	else:
		print('NO')
		break


(n, m) = map(int, input().split())
s = input()
t = input()
ind = -1
for i in range(len(s)):
	if s[i] == '*':
		ind = i
		break
if ind == -1 and s != t or len(s) > len(t) + 1:
	print('No')
elif s[0:ind] == t[0:ind] and s[ind + 1:] == t[len(t) - len(s) + ind + 1:]:
	print('Yes')
else:
	print('No')


def readNums(type=int):
	return list(map(type, input().split()))
(n, m) = readNums()
(a, b) = (input(), input())
p = a.find('*')
if p == -1:
	print('YES' if a == b else 'NO')
else:
	print('YES' if a[:p] == b[:p] and m - (n - p - 1) >= p and (a[p + 1:] == b[m - (n - p - 1):]) else 'NO')


nums = input()
nums = nums.split()
n = int(nums[0])
m = int(nums[1])
first = input()
second = input()
if first == '*':
	print('YES')
elif '*' not in first:
	if first == second:
		print('YES')
	else:
		print('NO')
else:
	first = first.split('*')
	fleft = first[0]
	fright = first[1]
	sleft = second[0:len(fleft)]
	if m < n:
		sright = second[len(fleft):]
	else:
		sright = second[-1 * len(fright):]
	if not fleft:
		if fright == sright:
			print('YES')
		else:
			print('NO')
	elif not fright:
		if fleft == sleft:
			print('YES')
		else:
			print('NO')
	elif fleft == sleft and fright == sright:
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if m < n - 1:
	print('NO')
elif '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
elif s[0] == '*':
	s1 = s[1:]
	t1 = t[m - n + 1:]
	if s1 == t1:
		print('YES')
	else:
		print('NO')
elif s[n - 1] == '*':
	s1 = s[:n - 1]
	t1 = t[:n - 1]
	if s1 == t1:
		print('YES')
	else:
		print('NO')
else:
	index = s.find('*')
	s1 = s[:index] + s[index + 1:]
	temp = n - index
	t1 = t[:index] + t[m - temp + 1:]
	if s1 == t1:
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
c = 10000
t += '!' * c
if s == t[:-c]:
	print('YES')
	exit(0)
if '*' not in s:
	print('NO')
	exit(0)
if len(s) - 1 > len(t) - c:
	print('NO')
	exit(0)
pref = ''
suf = ''
f = 0
for i in s:
	if i == '*':
		f = 1
	elif f == 0:
		pref += i
	else:
		suf += i
if t[:len(pref)] == pref and t[-len(suf) - c:-c] == suf:
	print('YES')
else:
	print('NO')


(n, m) = [int(i) for i in input().split()]
s = input()
t = input()
if not '*' in s:
	if n == m and s == t:
		print('YES')
	else:
		print('NO')
	exit()
if n > m + 1:
	print('NO')
	exit()
i = 0
while i < n and i < m and (s[i] != '*'):
	if s[i] != t[i]:
		print('NO')
		exit()
	i += 1
i = 1
while i <= n and i <= m and (s[len(s) - i] != '*'):
	if s[len(s) - i] != t[len(t) - i]:
		print('NO')
		exit()
	i += 1
print('YES')


(n, m) = map(int, input().split())
s = list(str(input()))
t = list(str(input()))
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
elif n == 1:
	print('YES')
elif n > m:
	s.remove('*')
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	indexOfAst = s.index('*')
	var1 = len(s[indexOfAst + 1:])
	if t[:indexOfAst] == s[:indexOfAst]:
		if s[indexOfAst + 1:] == t[-var1:]:
			print('YES')
		elif indexOfAst == len(s) - 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


t = 1
for test in range(1, t + 1):
	(n, m) = map(int, input().split())
	s = input()
	t = input()
	if n - m > 1:
		print('NO')
		continue
	tmp = s.find('*')
	if tmp == -1:
		if s == t:
			print('YES')
		else:
			print('NO')
	elif s[:tmp] == t[:tmp] and s[tmp + 1:] == t[m - (n - tmp - 1):]:
		print('YES')
	else:
		print('NO')


input()
p = input()
s = input()
if '*' not in p:
	if p != s:
		print('NO')
	else:
		print('YES')
else:
	(a, b) = p.split('*')
	if s.startswith(a) and s[len(a):].endswith(b):
		print('YES')
	else:
		print('NO')


input()
regex = input()
str_input = input()
if '*' not in regex:
	print('YES' if regex == str_input else 'NO')
else:
	(left, right) = regex.split('*')
	if str_input.startswith(left) and str_input.endswith(right) and (len(left) + len(right) <= len(str_input)):
		print('YES')
	else:
		print('NO')


_ = input()
s = input()
t = input()
k = s.split('*')
if len(k) == 1:
	if s == t:
		print('YES')
	else:
		print('NO')
	exit()
if t.startswith(k[0]):
	t = t[len(k[0]):]
	if t.endswith(k[1]):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


def check(string: str) -> bool:
	if string == '':
		return True
	else:
		for i in list(string):
			if not 'a' <= i <= 'z':
				return False
	return True
(n, m) = map(int, input().split())
sn = input()
len_sn = len(sn)
sm = input()
len_sm = len(sm)
if '*' in list(sn):
	sn = sn.split('*')
	if len_sm >= len_sn - 1 and sm.startswith(sn[0]) and sm.endswith(sn[1]) and check(sm[len(sn[0]):len(sm) - len(sn[1])]):
		print('YES')
	else:
		print('NO')
elif sn == sm:
	print('YES')
else:
	print('NO')


number = input()
(size1, size2) = number.split()
size1 = int(size1)
size2 = int(size2)
list1 = []
list2 = []
list3 = []
word1 = input()
word2 = input()
flag = True
starexist = False
for i in range(size1):
	if size1 - 1 > size2:
		flag = False
		break
	if word1[i] == '*':
		starexist = True
		break
	else:
		starexist = False
if starexist == True:
	for i in range(size1):
		if word1[i] != '*':
			list1.append(word1[i])
		else:
			break
	for i in range(size1 - 1, 0, -1):
		if word1[i] != '*':
			list2.append(word1[i])
		else:
			break
	for i in range(len(list2) - 1, -1, -1):
		list3.append(list2[i])
	for i in range(len(list1)):
		if word2[i] != list1[i]:
			flag = False
			break
	for i in range(len(list3) - 1, -1, -1):
		size3 = len(list3)
		difference = size2 - size3
		if word2[i + difference] != list3[i]:
			flag = False
if starexist == False:
	if word1 != word2:
		flag = False
	elif len(word1) != len(word2):
		flag = False
if flag == True:
	print('YES')
else:
	print('NO')


import sys

def input():
	return sys.stdin.readline().rstrip('\r\n')

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

def Num():
	return int(input())
(n, m) = List()
s = input()
t = input()
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
elif m + 1 == n or m >= n:
	(first, last) = s.split('*')
	if t.startswith(first) and t.endswith(last):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(n, m) = map(int, input().split())
gg = input()
c = input()
if gg.count('*') == 0:
	print('YES' if gg == c else 'NO')
	exit()
(f, s) = gg.split('*')
if c[:len(f)] == f:
	c = c[len(f):]
	if c[::-1][:len(s)] == s[::-1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
a = 0
f = 0
for i in s:
	if i == '*':
		a = s.index(i)
		x = s[0:a]
		z = s[a + 1:]
		break
	else:
		f = f + 1
w = n - (a + 1)
y = t[a:m - w]
if f == n:
	if s == t:
		print('YES')
	else:
		print('NO')
elif x + y + z == t:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s1 = str(input())
s2 = str(input())
check = s1.find('*')
if check == -1:
	if s1 == s2:
		print('YES')
	else:
		print('NO')
elif len(s1) - 1 > len(s2):
	print('NO')
else:
	k = s1[:check]
	check2 = s2.find(k)
	if check2 == 0:
		k2 = s1[check + 1:]
		k2 = k2[::-1]
		r2 = s2[::-1]
		check3 = r2.find(k2)
		if check3 == 0:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


(n, m) = map(int, input().split())
s1 = list(input())
s2 = input()
i = 0
seen = 0
j = 0
if '*' not in s1:
	if ''.join(s1) != s2:
		print('NO')
		exit()
while i < n and j < m:
	if s1[i] == '*':
		seen = 1
		break
		i += 1
	if not seen:
		if s1[i] != s2[j]:
			print('NO')
			exit()
		else:
			i += 1
			j += 1
i = n - 1
seen = 0
j = m - 1
while i >= 0 and j >= 0:
	if s1[i] == '*':
		seen = 1
		break
	if not seen:
		if s1[i] != s2[j]:
			print('NO')
			exit()
		else:
			i -= 1
			j -= 1
if '*' in s1:
	s1.remove('*')
s1 = ''.join(s1)
n = len(s1)
i = 0
j = 0
c = 0
while i < n and j < m:
	if s1[i] == s2[j]:
		i += 1
		j += 1
		c += 1
	else:
		j += 1
print('YES' if c == n else 'NO')


(_, s, t) = [input() for i in range(3)]
if '*' in s:
	(l, r) = s.split('*')
	print('YES' if len(r) + len(l) <= len(t) and t.startswith(l) and t.endswith(r) else 'NO')
else:
	print('YES' if s == t else 'NO')


[n, m] = [int(x) for x in input().split()]
s = input()
t = input()
ind = s.find('*')
if ind == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
elif m < n - 1:
	print('NO')
elif s[:ind] == t[:ind] and s[ind + 1:] == t[m - (n - ind - 1):]:
	print('YES')
else:
	print('NO')


lineone = input().split(' ')
n = int(lineone[0])
m = int(lineone[1])
s = input()
t = input()

def doAction(n, m, s, t):
	if n > m + 1:
		return False
	wildcardIndex = s.rfind('*')
	if wildcardIndex < 0:
		return s == t
	prefix = s[0:wildcardIndex] == t[0:wildcardIndex]
	sufix = s[wildcardIndex + 1:n] == t[wildcardIndex - n + 1 + m:m]
	w = t[wildcardIndex:wildcardIndex + m - n + 1]
	wIsValid = len(w) == 0 or (w.isalpha() and w.islower())
	return prefix and sufix and wIsValid
if doAction(n, m, s, t):
	print('YES')
else:
	print('NO')


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import add
import re
inf = float('inf')
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
(_, _) = r()
a = ip()
b = ip()
if '*' not in a:
	print('YES' if a == b else 'NO')
	exit()
arr = a.split('*')
print('YES' if b.startswith(arr[0]) and b.endswith(arr[1]) and (len(b) >= len(arr[0]) + len(arr[1])) else 'NO')


[n, m] = list(map(int, input().split()))
arr1 = list(input(''))
arr2 = list(input(''))
star = arr1.count('*')
if star == 0:
	if arr1 == arr2:
		print('YES')
	else:
		print('NO')
else:
	ind = arr1.index('*')
	if arr1[:ind] != arr2[:ind]:
		print('NO')
	else:
		k = n - ind - 1
		z = m - ind
		if k > z:
			print('NO')
		else:
			try:
				if arr1[ind + 1:] != arr2[m - k:]:
					print('NO')
				else:
					print('YES')
			except:
				print('NO')


(n, m) = (int(x) for x in input().split())
a = input()
b = input()
if '*' not in a:
	if a == b:
		print('YES')
	else:
		print('NO')
	quit()
(l, r) = a.split('*')
if len(b) >= len(a) - 1:
	if l == b[:len(l)] and r == b[len(b) - len(r):]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(n, m) = map(int, input().split())
a = input()
b = input()
c = 1
if n != m and a.count('*') == 0:
	c = 0
if a.count('*') != 0 and n > m + 1:
	c = 0
for i in range(len(a)):
	if c == 0:
		continue
	if a[i] == '*':
		break
	if a[i] != b[i]:
		c = 0
ind = 1
for i in range(len(b) - 1, -1, -1):
	if c == 0:
		continue
	if a[len(a) - ind] == '*':
		break
	if a[len(a) - ind] != b[i]:
		c = 0
	ind += 1
if c == 1 and len(a) <= len(b) + 1:
	print('YES')
else:
	print('NO')


import sys
(n, m) = map(int, input().split())
(s, t) = (line.strip() for line in sys.stdin)
p = s.find('*')
if p == -1:
	print(('NO', 'YES')[s == t])
elif len(s) - 1 > len(t):
	print('NO')
else:
	print(('NO', 'YES')[t.startswith(s[:p]) and t.endswith(s[p + 1:])])


(n, m) = list(map(int, input().split()))
s = input()
t = input()
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	a = s.split('*')
	if len(t) >= len(s) - 1 and t[:len(a[0])] == a[0] and (len(a[1]) == 0 or t[-len(a[1]):] == a[1]):
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if len(s) - 1 > m:
	print('NO')
elif s == '*':
	print('YES')
elif '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	for i in range(len(s)):
		if s[i] == '*':
			pos = i
			break
	if s[0:pos] == t[0:pos] and s[pos + 1:] == t[m - (n - pos) + 1:]:
		print('YES')
	else:
		print('NO')


s = input()
s = input()
if s == '*':
	print('YES')
elif s.find('*') == -1:
	ss = input()
	if s == ss:
		print('YES')
	else:
		print('NO')
else:
	s = s.split('*')
	l = s[0]
	r = s[1]
	s = input()
	if l == '':
		if s[-len(r):] == r:
			print('YES')
		else:
			print('NO')
	elif r == '':
		if s[:len(l)] == l:
			print('YES')
		else:
			print('NO')
	elif len(l) + len(r) > len(s):
		print('NO')
	elif s[:len(l)] == l and s[-len(r):] == r:
		print('YES')
	else:
		print('NO')


import sys
from collections import deque
import bisect
for _ in range(1):
	(n, m) = map(int, input().split())
	s = input()
	t = input()
	if s == t:
		print('YES')
		continue
	if s.count('*') == 1:
		e = list(s.split('*'))
		flag = 1
		visited = set()
		for i in range(len(e[0])):
			x = e[0][i]
			if i >= m:
				flag = 0
				break
			y = t[i]
			visited.add(i)
			if x != y:
				flag = 0
				break
		i = m - 1
		j = len(e[1]) - 1
		while j > -1:
			if i in visited:
				flag = 0
				break
			x = e[1][j]
			if i < 0:
				flag = 0
				break
			if x != t[i]:
				flag = 0
				break
			j -= 1
			i -= 1
		if flag:
			print('YES')
			continue
	print('NO')


def solve(s, t):
	ss = s.split('*')
	if len(ss) == 1:
		return ss[0] == t
	else:
		return t.startswith(ss[0]) and t.endswith(ss[1]) and (len(t) >= len(s) - 1)
input()
s = input()
t = input()
if solve(s, t):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
k = -1
ans = 'YES'
for i in range(min(n, m)):
	if s[i] == '*':
		k = i
		break
	if s[i] != t[i]:
		ans = 'NO'
		break
if k == -1:
	if n == m + 1 and s[n - 1] == '*':
		pass
	elif n != m:
		ans = 'NO'
elif k != -1:
	for i in range(n - k - 1):
		if s[n - i - 1] != t[m - i - 1]:
			ans = 'NO'
			break
		if m - i - 1 < k:
			ans = 'NO'
			break
print(ans)


(n, m) = map(int, input().split())
x = input()
y = input()
if x.count('*') == 1 and len(x) <= len(y) + 1:
	z = x.index('*')
	if ''.join(x[:z]) == ''.join(y[:z]) and ''.join(x[z + 1:]) == ''.join(y[len(y) - len(x[z + 1:]):]):
		print('YES')
	else:
		print('NO')
elif x.count('*') == 0:
	if x == y:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
from sys import exit
if '*' in s:
	if n - m > 1:
		print('NO')
		exit()
elif n - m != 0:
	print('NO')
	exit()
for i in range(min(n, m)):
	if s[i] != t[i]:
		if s[i] != '*':
			print('NO')
			exit()
		break
(e, r) = (n - 1, m - 1)
for i in range(min(n, m)):
	if s[e] != t[r]:
		if s[e] != '*':
			print('NO')
			exit()
		break
	(e, r) = (e - 1, r - 1)
print('YES')


(n, m) = input().split(' ')
s = input()
t = input()
i = s.find('*')
j = int(m) - (int(n) - (i + 1))
if i == -1 and s == t:
	print('Yes')
elif s[:i] == t[:i]:
	s = s[i + 1:]
	t = t[i:]
	if len(s) == 0 or t[-len(s):] == s:
		print('Yes')
	else:
		print('No')
else:
	print('No')


(n, m) = map(int, input().split())
s = input()
t = input()
if n > m + 1:
	print('NO')
elif s == t:
	print('YES')
elif '*' not in s:
	print('NO')
else:
	(front, back) = s.split('*')
	match = 1
	for i in range(len(front)):
		if front[i] != t[i]:
			match = 0
			break
	if match == 0:
		print('NO')
	else:
		for j in range(len(back)):
			if back[len(back) - 1 - j] != t[len(t) - 1 - j]:
				match = 0
				break
		if match == 0:
			print('NO')
		else:
			print('YES')


_ = input()
s = input()
s1 = input()
if '*' in s:
	s = s.split('*')
	s[1] = s[1][::-1]
	s2 = s1[::-1]
	if len(s[0]) + len(s[1]) > len(s1):
		print('NO')
	elif s1[:len(s[0])] == s[0] and s2[:len(s[1])] == s[1]:
		print('YES')
	else:
		print('NO')
elif s == s1:
	print('YES')
else:
	print('NO')


(n, m) = input().split()
s = input()
t = input()
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	(a, b) = s.split('*')
	if t[0:len(a)] == a and t[len(t) - len(b):len(t)] == b and (len(t) >= len(s) - 1):
		print('YES')
	else:
		print('NO')


from enum import *
from copy import *
from sys import *
from collections import *
from itertools import *
from functools import *
from math import *

def l2i(fr=None):
	return map_type_to_fr(int, fr)[0]

def i2i(fr=None):
	return l2i(fr)

def dbg(*args):
	print(*args, file=stderr)

def dbv(var_name):
	print(f'{var_name} = {eval(var_name)}', file=stderr)

def map_type_to_fr(t, fr):
	global GETLINE_OFFSET
	if fr is None:
		if RUNNING_ON_MY_PC:
			fr = TEST_INP[GETLINE_OFFSET].split()
			GETLINE_OFFSET += 1
		else:
			fr = input().split()
	return list(map(t, fr))

def mis(fr=None):
	return map_type_to_fr(int, fr)

def mbs(fr=None):
	return map_type_to_fr(bool, fr)

def gs(fr=None):
	return map_type_to_fr(str, fr)[0]
import os
import sysconfig
RUNNING_ON_MY_PC = os.name == 'nt' and platform == 'win32' and (sysconfig.get_platform() == 'win-amd64')
GETLINE_OFFSET = 0
TEST_INP = '9 6\ngfgf*gfgf\ngfgfgf\n\n'.split('\n')
(n, m) = mis()
s = gs()
t = gs()
idx = s.find('*')
if idx == -1:
	print('YES' if s == t else 'NO')
else:
	if s[:idx] != t[:idx]:
		print('NO')
		exit()
	t_from = m - (n - idx - 1)
	if t_from < idx:
		print('NO')
		exit()
	if s[idx + 1:] != t[t_from:]:
		print('NO')
	else:
		print('YES')


(n, m) = map(int, input().split())
s = input()
t = input()
k = 0
j = 0
if s.count('*') == 0:
	if t == s:
		print('YES')
	else:
		print('NO')
else:
	k = s.find('*')
	l = s[k + 1:]
	q = t[k:]
	if t[:k] == s[:k] and q[::-1].find(l[::-1]) == 0:
		print('YES')
	else:
		print('NO')


input()
s = input()
t = input()
if '*' in s:
	(s1, s2) = s.split('*')
	if (t[:len(s1)] == s1 or s1 == '') and (t[-len(s2):] == s2 or s2 == '') and (len(t) >= len(s1) + len(s2)):
		print('YES')
	else:
		print('NO')
elif t == s:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
pos = s.find('*')
if pos != -1:
	left = s[:pos]
	right = s[pos + 1:]
	if m >= len(left) + len(right) and t[:len(left)] == left and (t[m - len(right):] == right):
		print('YES')
	else:
		print('NO')
elif s == t:
	print('YES')
else:
	print('NO')


(x, y) = input().split()
(n, m) = (int(x), int(y))
s = input()
t = input()
if '*' not in s and s != t:
	print('NO')
elif '*' not in s and s == t:
	print('YES')
elif len(s) > len(t) + 1:
	print('NO')
elif s == '*':
	print('YES')
else:
	ok = True
	i = 0
	while s[i] != '*':
		if s[i] != t[i]:
			print('NO')
			ok = False
			break
		i += 1
	(j, k) = (len(t) - 1, len(s) - 1)
	while s[k] != '*' and ok:
		if s[k] != t[j]:
			ok = False
			print('NO')
			break
		k -= 1
		j -= 1
	if ok:
		print('YES')


from sys import stdin, stdout, setrecursionlimit
from gc import disable
gets = input
puts = print
input = stdin.readline
print = stdout.write

def main() -> int:
	disable()
	(n, m) = map(int, input().split())
	s = gets()
	t = gets()
	if n - 1 > m:
		print('NO')
		return 0
	dot = s.find('*')
	if dot == -1:
		print('YES' if s == t else 'NO')
		return 0
	if s[:dot] + t[dot:m - (n - dot - 1)] + s[dot + 1:] == t:
		print('YES')
	else:
		print('NO')
	return 0
main()


(n, m) = map(int, input().split())
s = input()
t = input()
if '*' not in s:
	res = s == t
else:
	(a, b) = s.split('*')
	res = len(a) + len(b) <= len(t)
	res &= not a or a == t[:len(a)]
	res &= not b or t[-len(b):] == b
print('YES' if res else 'NO')


(n, m) = list(map(int, input().split()))

def reverse(s):
	b = []
	b.extend(s)
	b.reverse()
	return b
if m < n - 1:
	print('NO')
else:
	a = input()
	if '*' in a:
		(st, nd) = a.split('*')
		rd = input()
		len_2 = len(nd)
		len_1 = len(st)
		if rd[:len_1] == st and reverse(rd)[:len_2] == reverse(nd):
			print('YES')
		else:
			print('NO')
	else:
		st = a
		rd = input()
		if st == rd:
			print('YES')
		else:
			print('NO')


(n, m) = map(int, input().split())
s = str(input())
t = str(input())
if s.count('*') == 0 and s != t:
	print('NO')
elif s.count('*') == 0 and s == t:
	print('YES')
elif s.count('*') != 0:
	k = int(s.find('*'))
	s1 = s[::-1]
	t1 = t[::-1]
	if s[0:k] == t[0:k] and s1[0:n - k - 1] == t1[0:n - k - 1] and (m - n >= -1):
		print('YES')
	else:
		print('NO')


input()
s = input()
t = input()
l = s.split('*')
n = len(s)
m = len(t)
if len(l) == 1:
	if l[0] != t:
		print('NO')
		exit()
	else:
		print('YES')
		exit()
if m < n - 1:
	print('NO')
	exit()
if t.startswith(l[0]) is False:
	print('NO')
	exit()
k = len(t) - len(l[0])
t = t[-k:]
if t.endswith(l[1]):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
(s, t) = (input(), input())
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
	return
s1 = s[:s.find('*')]
s2 = s[s.find('*') + 1:]
if t[:len(s1)] == s1 and t[len(t) - len(s2):] == s2 and (len(s1) + len(s2) <= len(t)):
	print('YES')
else:
	print('NO')


import sys
input()
A = str(input())
B = str(input())
if '*' not in A:
	if A == B:
		print('YES')
	else:
		print('NO')
	sys.exit(0)
(p1, p2) = A.split('*')
if (B[0:len(p1)] == p1 or len(p1) == 0) and (B[len(p1):][-len(p2):] == p2 or len(p2) == 0):
	print('YES')
else:
	print('NO')


import sys
(n, m) = map(int, input().split())
mask = input()
file = input()
if '*' not in mask:
	if mask == file:
		print('YES')
	else:
		print('NO')
	sys.exit()
inx = mask.index('*')
s1 = mask[:inx]
s2 = mask[inx + 1:]
if s1 in file and s2 in file:
	ix1 = file.index(s1)
	ix2 = file.rindex(s2)
	if ix1 == 0 and ix2 == m - len(s2) and (ix1 + len(s1) - 1 < ix2):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if '*' in s:
	(front, back) = s.split('*')
	if len(t) >= len(s) - 1 and t.startswith(front) and t.endswith(back):
		print('YES')
	else:
		print('NO')
else:
	print('YES' if s == t else 'NO')


inpt = [int(i) for i in input().split()]
word_1 = '123' + input() + '123'
word_2 = '123' + input() + '123'
if len(word_1) - len(word_2) > 1:
	print('NO')
else:
	word_1 = word_1.split('*')
	has = True
	for word in word_1:
		if word_2.find(word) == -1:
			has = False
	if has:
		print('YES')
	else:
		print('NO')


def main():
	input()
	regex = input()
	str = input()
	if '*' not in regex:
		if str == regex:
			print('YES')
		else:
			print('NO')
		exit(0)
	(a, b) = regex.split('*')
	if len(a + b) <= len(str) and str.startswith(a) and str.endswith(b):
		print('YES')
	else:
		print('NO')
main()


import sys
input = sys.stdin.readline

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

def listStr():
	return list(input().strip())
import collections as col
import math

def solve():
	(N, M) = getInts()
	S = listStr()
	T = listStr()
	if '*' not in S:
		return 'YES' if S == T else 'NO'
	if len(T) < len(S) - 1:
		return 'NO'
	w = S.index('*')
	if w == 0:
		return 'YES' if S[1:] == T[M - (N - 1):] else 'NO'
	if w == N - 1:
		return 'YES' if S[:-1] == T[:N - 1] else 'NO'
	S1 = S[:w]
	S2 = S[w + 1:]
	T1 = T[:len(S1)]
	T2 = T[-len(S2):]
	return 'YES' if S1 == T1 and S2 == T2 else 'NO'
print(solve())


(n, m) = map(int, input().split())
s = input()
t = input()
k = -1
for i in range(n):
	if s[i] == '*':
		k = i
		break
if s[0:i] == t[0:i] and s[i + 1:n] == t[m - n + i + 1:m]:
	if k == -1 and s != t or n > m + 1:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


while True:
	eminems = input().split()
	n = int(eminems[0])
	m = int(eminems[1])
	s = input()
	t = input()
	s = s.split('*')
	if len(s) == 1:
		if s[0] == t:
			print('YES')
		else:
			print('NO')
	elif (t[0:len(s[0])] == s[0] or len(s[0]) == 0) and (t[-len(s[1]):] == s[1] or len(s[1]) == 0) and (n <= m + 1):
		print('YES')
	else:
		print('NO')
	break


(n, m) = list(map(int, input().split(' ')))
s = str(input())
t = str(input())
if s == '*':
	print('YES')
elif s.replace('*', '') == t:
	print('YES')
elif s[0] == '*':
	s = s.replace('*', '')
	if t.rfind(s) == len(t) - len(s):
		print('YES')
	else:
		print('NO')
elif s[len(s) - 1] == '*':
	s = s.replace('*', '')
	if t.find(s) == 0:
		print('YES')
	else:
		print('NO')
elif '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	(s1, s2) = s.split('*')
	if s1 in t:
		index1 = t.index(s1)
		if index1 == 0 and s2 in t[index1 + len(s1):]:
			index2 = t.index(s2, index1 + len(s1))
			if index2 > index1 and index2 + len(s2) == len(t):
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	else:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
s1 = s[::-1]
d = -1
if n > m + 1:
	print('NO')
else:
	for i in range(0, n):
		if s[i] == '*':
			d = i
	if d != -1:
		if s[0:d] == t[0:d] and s[d + 1:n] == t[m - n + d + 1:m]:
			print('YES')
		else:
			print('NO')
	elif s == t:
		print('YES')
	else:
		print('NO')


h = input().split(' ')
n = int(h[0])
m = int(h[1])
s = input()
t = input()
if n > m + 1:
	print('NO')
	exit()
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
	exit()
arr = s.split('*')
lt = len(t)
if arr[0] == t[:len(arr[0])] and arr[1] == t[lt - len(arr[1]):lt]:
	print('YES')
else:
	print('NO')


def SWPM():
	n_m = input()
	x1 = n_m.find(' ')
	n = int(n_m[:x1])
	m = int(n_m[x1 + 1:])
	s = input()
	t = input()
	q = s.find('*')
	p = q + 1
	o = p + m - n
	if q == -1 and s == t:
		print('YES')
	elif q != -1 and n - m <= 1 and (s[:q] == t[:q]) and (s[p:] == t[o:]):
		print('YES')
	else:
		print('NO')
SWPM()


import re
(n, m) = input().split(' ')
s = input()
t = input()
l = s.split('*')
regex_start = '^' + l[0]
if len(l) > 1:
	regex_end = '' + l[1] + '$'
if len(l) == 1:
	if s == t:
		print('YES')
	else:
		print('NO')
elif len(l[0]) + len(l[1]) > len(t):
	print('NO')
elif re.search(regex_start, t) and re.search(regex_end, t):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if '*' in s:
	x = s.index('*')
	if t[:x] == s[:x] and t[x:].endswith(s[x + 1:]):
		print('YES')
	else:
		print('NO')
else:
	print('YES' if s == t else 'NO')


(N, M) = map(int, input().split())
s = input()
t = input()
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
elif len(s) - 1 > len(t):
	print('NO')
else:
	s = s.split('*')
	try:
		if s[0] == t[:len(s[0])] and s[1] == t[len(t) - len(s[1]):]:
			print('YES')
		else:
			print('NO')
	except:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if n - 1 > m:
	print('NO')
else:
	try:
		a = s.index('*')
	except:
		a = -1
	if a == -1:
		if s == t:
			print('YES')
		else:
			print('NO')
	else:
		f = True
		for i in range(a):
			if s[i] != t[i]:
				print('NO')
				exit()
		i = 1
		while m - i >= a and n - i > a:
			if s[n - i] != t[m - i]:
				print('NO')
				exit()
			i += 1
		print('YES')


(a, b) = [*open(0)][1:]
if '*' in a:
	(x, y) = a.split('*')
	r = b.startswith(x) and b[len(x):].endswith(y)
else:
	r = a == b
print('NYOE S'[r::2])


import sys

def input():
	return sys.stdin.readline()[:-1]
from collections import deque
(n, m) = [int(x) for x in input().split()]
s = deque([x for x in input()])
t = deque([x for x in input()])
while s and t and (s[0] == t[0]):
	s.popleft()
	t.popleft()
while s and t and (s[-1] == t[-1]):
	s.pop()
	t.pop()
if not s and (not t) or (len(s) == 1 and s[0] == '*'):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
if s.count('*') == 1:
	if t.startswith(s[:s.index('*')]) & t[len(s[:s.index('*')]):].endswith(s[s.index('*') + 1:]):
		print('YES')
	else:
		print('NO')
elif s == t:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
tmp = s.find('*')
len_ = len(s) - tmp - 1
if len_ == 0:
	if s[:tmp] == t[:tmp]:
		print('YES')
	else:
		print('NO')
	exit()
if tmp != -1:
	if len(s) - 1 > len(t):
		print('NO')
		exit()
	if t[:tmp] == s[:tmp] and t[-len_:] == s[-len_:]:
		print('YES')
		exit()
elif s == t:
	print('YES')
	exit()
print('NO')


(n, m) = input().strip().split(' ')
(n, m) = (int(n), int(m))
s = input().strip()
t = input().strip()
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	(x, y) = s.split('*')
	if t.startswith(x) and t.endswith(y) and (len(x) + len(y) <= len(t)):
		print('YES')
	else:
		print('NO')


(n, m) = [int(j) for j in input().split()]
s = input()
t = input()
if '*' in s:
	star = s.find('*')
	if n <= m + 1 and s[:star] == t[:star] and (s[star + 1:] == t[m - (n - 1 - star):]):
		print('YES')
	else:
		print('NO')
elif s == t:
	print('YES')
else:
	print('NO')


import sys
(n, m) = map(int, input().split())
s = input()
s1 = input()
if s == s1:
	print('YES')
	sys.exit()
can = True
z = 0
for i in range(min(n, m)):
	if s[i] != s1[i] and s[i] != '*':
		can = False
		break
	if s[i] != s1[i] and s[i] == '*':
		z = i - 1
		break
x = n - 1
y = m - 1
while x > z and y > z:
	if s[x] != s1[y] and s[x] != '*':
		can = False
		break
	if s[x] != s1[y] and s[x] == '*':
		break
	x -= 1
	y -= 1
if can and s[x] == '*' and (n - 1 <= m):
	print('YES')
else:
	print('NO')


num_str = input()
list_1 = num_str.split()
m = int(list_1[0])
n = int(list_1[1])
str_m = input()
str_n = input()
b = True
count = 0
for i in range(m):
	if str_m[i] != '*' and i < n:
		if str_n[i] != str_m[i]:
			print('No')
			b = False
			break
		else:
			count += 1
	elif str_m[i] != '*' and i >= n:
		print('No')
		b = False
		break
	else:
		str_1 = str_m[i + 1:m]
		if i <= n - m + i + 1:
			str_2 = str_n[n - m + i + 1:n]
			if str_1 == str_2:
				print('Yes')
				b = False
				break
			else:
				print('No')
				b = False
				break
		else:
			print('No')
			b = False
			break
if b:
	if count == n:
		print('Yes')
	else:
		print('No')


(n, m) = input().split()
(n, m) = (int(n), int(m))
s = input()
t = input()
quit = False
if not len(s) - 1 <= len(t):
	print('NO')
	quit = True
if '*' not in s and len(s) != len(t):
	print('NO')
	quit = True
if not quit:
	index = 0
	for i in s:
		if i == '*':
			break
		index += 1
	s1 = s[:index]
	s2 = s[index + 1:]
	if s1 == t[:len(s1)]:
		if s2 == t[len(t) - len(s2):]:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
orgt = t
if n == 2 and '*' in s:
	print('YES' if s.replace('*', t[:m - 1]) == t or s.replace('*', t[1:]) == t else 'NO')
	exit(0)
if '*' not in s or n - m >= 1:
	if s == t:
		print('YES')
	elif n - m == 1:
		if s.replace('*', '') == t:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
else:
	for i in range(n - 1):
		if s[i + 1] == '*':
			t = t.replace(s[:i + 1], '', 1)
			break
	for i in range(n - 1, -1, -1):
		if s[i - 1] == '*':
			t = t.replace(s[i:], '', 1)
			break
	if s.replace('*', t) == orgt:
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
q = t[::-1]
if n > m + 1:
	print('NO')
	exit(0)
if not '*' in s:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	k = s.index('*')
	l = n - k - 1
	if s[:k] == t[:k] and s[k + 1:][::-1] == q[:l]:
		print('YES')
	else:
		print('NO')


temp = input()
s = input()
t = input()
flag = 0
if '*' in s:
	ans = []
	for x in s.split('*'):
		ans.append(x)
	if ans[0] == '' and ans[1] == '':
		flag = 1
	elif ans[0] == '':
		if ans[1] == t[-len(ans[1]):]:
			flag = 1
	elif ans[1] == '':
		if ans[0] == t[:len(ans[0])]:
			flag = 1
	elif ans[0] == t[:len(ans[0])] and ans[1] == t[-len(ans[1]):] and (len(s) - 1 <= len(t)):
		flag = 1
elif s == t:
	flag = 1
if flag:
	print('YES')
else:
	print('NO')


(n, m) = [int(x) for x in input().split()]
s = input()
t = input()
idx = 0
ans = 0
if m < n - 1:
	print('NO')
	exit(0)
if not '*' in s:
	if s == t:
		print('YES')
	else:
		print('NO')
	exit(0)
for x in range(n):
	if s[x] == '*':
		idx = x
		break
lol = m - (n - idx) + 1
if s[:idx] == t[:idx] and s[idx + 1:] == t[lol:]:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
a = s.find('*')
s = s.replace('*', t[a:a + m - n + 1])
if s == t:
	print('YES')
else:
	print('NO')


_ = input()
s = str(input())
t = str(input())
pos = s.find('*')
if s == t:
	print('YES')
elif s == '*':
	print('YES')
elif pos == -1:
	print('NO')
elif s[:pos] == t[:pos] and t.find(s[pos + 1:], pos) >= 0 and (s[pos + 1:] == t[-len(s[pos + 1:]):] or pos + 1 == len(s)):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split(' '))
s = input()
t = input()
a = []
b = []
for i in s:
	a.append(i)
for i in t:
	b.append(i)
s = a
t = b
if m < n or s.count('*') == 0:
	if s.count('*') != 0:
		s.remove('*')
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	i = 0
	j = n - 1
	while i < n and s[i] != '*':
		if s[i] != t[i]:
			print('NO')
			exit()
		i += 1
	i = n - 1
	j = m - 1
	while i >= 0 and s[i] != '*':
		if s[i] != t[j]:
			print('NO')
			exit()
		i -= 1
		j -= 1
	print('YES')


(n, m) = map(int, input().split())
if n > 0:
	s1 = input()
if m > 0:
	s2 = input()
ind = -1
for i in range(len(s1)):
	if s1[i] == '*':
		ind = i
		break
if ind == -1:
	if s1 == s2:
		print('YES')
	else:
		print('NO')
else:
	if len(s2) + 1 < len(s1):
		print('NO')
		exit()
	if len(s2) >= ind:
		if s1[:ind] == s2[:ind]:
			s2 = s2[ind:]
			d = len(s1) - (ind + 1)
			if s2[len(s2) - d:] == s1[ind + 1:]:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	else:
		print('NO')


(a, b) = map(int, input().split())
s = input()
t = input()
num = -1
for i in range(a):
	if s[i] == '*':
		num = i
		break
if num == -1:
	if s == t:
		print('YES')
	else:
		print('NO')
elif a - b > 1:
	print('NO')
elif s[0:num] == t[0:num] and s[num + 1:a] == t[b - a + num + 1:b]:
	print('YES')
else:
	print('NO')


x = list(map(int, input().strip().split()))
s = input()
t = input()
if '*' not in s:
	if s == t:
		print('YES')
	else:
		print('NO')
else:
	(p, q) = s.split('*')
	x = len(p)
	y = len(q)
	if t[:x] == p and t[::-1][:y][::-1] == q and (len(t) >= len(s) - 1):
		print('YES')
	else:
		print('NO')


def solve():
	(n, m) = map(int, input().split())
	(s, t) = (input().strip(), input().strip())
	if s.find('*') >= 0:
		ai = s.find('*')
		if t.find(s[:ai]) != 0:
			print('NO')
			return
		if ai == n - 1:
			print('YES')
		else:
			t2 = t[ai:]
			i2 = t2.rfind(s[ai + 1:])
			print('YES' if 0 <= i2 and t2[i2:] == s[ai + 1:] else 'NO')
	else:
		print('YES' if s == t else 'NO')
solve()


(n, m) = list(map(int, input().split()))
padrao = input()
string = input()
if n > m + 1:
	print('NO')
elif '*' in padrao:
	(front, end) = padrao.split('*')
	if len(end) != 0:
		aux = string[-len(end):]
	else:
		aux = ''
	if aux != end:
		print('NO')
	else:
		aux = string[:len(front)]
		if aux == front:
			aux = string[len(front):-len(end)]
			flag = True
			if len(aux) != 0 and aux.islower() == False:
				flag = False
			for i in range(len(aux)):
				if not aux[i].isalpha():
					flag = False
					break
			if flag:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
elif padrao == string:
	print('YES')
else:
	print('NO')


def solve():
	(n, m) = map(int, input().split())
	s = input()
	t = input()
	if s == t:
		return 'YES'
	star = s.find('*')
	s1 = s[:star]
	s2 = s[star + 1:]
	if s1 == t[:star]:
		if len(s2) == 0 or s2 == t[star:][-len(s2):]:
			return 'YES'
	return 'NO'
print(solve())


(n, m) = map(int, input().split())
x = input()
y = input()
a = []
b = []
c = 0
for i in range(len(x)):
	if x[i] != '*':
		a.append(x[i])
	else:
		c += 1
		break
for j in range(i + 1, n):
	b.append(x[j])
if c == 0:
	f = 1
	if n != m:
		f = 0
	else:
		for i in range(n):
			if x[i] != y[i]:
				f = 0
				break
	if f == 0:
		print('NO')
	else:
		print('YES')
elif len(x) - 1 > len(y):
	print('NO')
else:
	i = x.index('*')
	a = x[0:i]
	b = y[0:i]
	c = x[i + 1:]
	d = y[len(y) - (len(x) - i - 1):]
	if a == b and c == d:
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
s = input()
t = input()
b = False
for e in s:
	if e == '*':
		b = True
		break
if b == False and s != t or len(s) - 1 > len(t):
	print('NO')
elif b == False and s == t:
	print('YES')
else:
	i = 0
	while s[i] != '*':
		if s[i] != t[i]:
			print('NO')
			break
		i += 1
	else:
		i = -1
		while s[i] != '*':
			if s[i] != t[i]:
				print('NO')
				break
			i -= 1
		else:
			print('YES')


(n, m) = map(int, input().split())
(s, t) = (input(), input())
if s.count('*') == 0:
	if s == t:
		exit(print('YES'))
	else:
		exit(print('NO'))
(a, b) = s.split('*')
l1 = len(a)
l2 = len(b)
if a == t[:l1]:
	if m + 1 >= n:
		if b == t[m - l2:m]:
			exit(print('YES'))
		else:
			exit(print('NO'))
	else:
		exit(print('NO'))
else:
	exit(print('NO'))