AtCoder Beginner Contest 054 - Template Matching

You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.

A pixel is the smallest element of an image, and in this problem it is a square of size 1×1.

Also, the given images are binary images, and the color of each pixel is either white or black.  
In the input, every pixel is represented by a character: . corresponds to a white pixel, and # corresponds to a black pixel.

The image A is given as N strings A_1,...,A_N.

The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1≦i,j≦N).

Similarly, the template image B is given as M strings B_1,...,B_M.

The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1≦i,j≦M).  
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.  

-----Constraints-----
 - 1≦M≦N≦50 
 - A_i is a string of length N consisting of # and ..
 - B_i is a string of length M consisting of # and ..

-----Input-----
The input is given from Standard Input in the following format:
N M
A_1
A_2
:  
A_N
B_1
B_2
:  
B_M

-----Output-----
Print Yes if the template image B is contained in the image A. Print No otherwise.

-----Sample Input-----
3 2
#.#
.#.
#.#
#.
.#

-----Sample Output-----
Yes

The template image B is identical to the upper-left 2 × 2 subimage and the lower-right 2 × 2 subimage of A. Thus, the output should be Yes.

Difficulty: EASY

Starter code:

Solutions:
(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
r = any(([r[j:j + m] for r in a[i:i + m]] == b for i in range(n - m + 1) for j in range(n - m + 1)))
print('Yes' if r else 'No')


import numpy as np
(n, m) = map(int, input().split())
A = np.array([list(input()) for i in range(n)])
B = np.array([list(input()) for j in range(m)])
for i in range(n - m + 1):
	for j in range(n - m + 1):
		if np.all(B == A[i:i + m, j:j + m]):
			print('Yes')
			return
print('No')


(N, M) = list(map(int, input().split()))
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
flag = 0
for i in range(N - M + 1):
	for j in range(N - M + 1):
		if [line[j:j + M] for line in A[i:i + M]] == B:
			flag = 1
print('Yes' if flag == 1 else 'No')


(n, m) = map(int, input().split(' '))
i1 = [input() for i in range(n)]
i2 = [input() for i in range(m)]
for i in range(0, n - m + 1):
	for j in range(0, n - m + 1):
		si = [x[j:j + m] for x in i1[i:i + m]]
		if si == i2:
			print('Yes')
			exit(0)
print('No')


(n, m) = list(map(int, input().split()))
pic_a = [input() for _ in range(n)]
pic_b = [input() for _ in range(m)]
top = pic_b[0][0]
if m == 1:
	for line_a in pic_a:
		for chr_a in line_a:
			if top == chr_a:
				print('Yes')
				return
	print('No')
	return
for (i, line_a) in enumerate(pic_a[:-m + 1]):
	for (j, chr_a) in enumerate(line_a[:-m + 1]):
		if top == chr_a:
			for (k, line_b) in enumerate(pic_b):
				if line_b != pic_a[i + k][j:j + m]:
					break
			else:
				print('Yes')
				return
print('No')


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n - m + 1):
	for g in range(n - m + 1):
		d = []
		for l in range(m):
			d.append(a[l + i][g:g + m])
		if d == b:
			print('Yes')
			exit()
print('No')


(N, M) = map(int, input().split())
A = []
for i in range(N):
	A.append(input())
B = []
for i in range(M):
	B.append(input())
for i in range(N - M + 1):
	for j in range(N - M + 1):
		for k in range(M):
			if A[i + k][j:j + M] != B[k]:
				break
			if k == M - 1:
				print('Yes')
				return
print('No')


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in a:
	for j in b:
		if j not in i:
			print('No')
			exit()
print('Yes')


(n, m) = [int(x) for x in input().split()]
a = []
for i in range(n):
	a.append(list(input()))
b = []
for i in range(m):
	b.append(list(input()))
res = 'No'
for i in range(n - m + 1):
	for j in range(n - m + 1):
		flag = True
		for k in range(m):
			for l in range(m):
				if a[k + i][l + j] != b[k][l]:
					flag = False
		if flag:
			res = 'Yes'
print(res)


(n, m) = map(int, input().split())
a = [list(input()) for i in range(n)]
b = [list(input()) for i in range(m)]
exist = False
for i in range(n - m + 1):
	for j in range(n - m + 1):
		match = True
		for k in range(m):
			for l in range(m):
				if a[i + k][j + l] != b[k][l]:
					match = False
		if match:
			exist = True
print('Yes' if exist else 'No')


(n, m) = list(map(int, input().split()))
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]
r = n - m + 1
for x in range(r ** 2):
	for y in range(m ** 2):
		if a[x // r + y // m][x % r + y % m] != b[y // m][y % m]:
			break
	else:
		print('Yes')
		break
else:
	print('No')


(n, m) = [int(i) for i in input().split()]
a = [input() for i in range(n)]
b = [input() for i in range(m)]
result = True
for i in range(m):
	if (b[i] in a[i]) == False:
		result = False
		break
print('Yes' if result else 'No')


import sys
(n, m) = list(map(int, input().split()))
(a, b) = ([], [])
for _ in range(n):
	a.append(input())
for _ in range(m):
	b.append(input())
for i in range(0, n - m + 1):
	for j in range(0, n - m + 1):
		for k in range(m * m):
			if a[i + k // m][j + k % m] != b[k // m][k % m]:
				break
			elif k == m * m - 1:
				print('Yes')
				return
print('No')


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		a1 = [a[k][j:j + m] for k in range(i, i + m)]
		if a1 == b:
			print('Yes')
			exit()
print('No')


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
flg = False
for i in range(n - m + 1):
	for j in range(n - m + 1):
		if all([b[l] == a[i + l][j:j + m] for l in range(m)]):
			flg = True
			break
print('Yes' if flg else 'No')


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(input())
b = []
for i in range(m):
	b.append(input())
flag = 0
judge = []
for i in range(n - m + 1):
	judge = []
	for j in range(n - m + 1):
		judge = []
		for k in range(m):
			judge.append(a[i + k][j:j + m])
		if judge == b:
			flag += 1
if flag == 0:
	print('No')
else:
	print('Yes')


(N, M) = list(map(int, input().split()))
A = []
B = []
clear = 0
same = 0
for i in range(N):
	A.append(str(input()))
for i in range(M):
	B.append(str(input()))
for i in range(N - M + 1):
	for j in range(N - M + 1):
		same = 0
		for k in range(M):
			if A[i + k][j:j + M] == B[k]:
				same += 1
			else:
				break
		if same == M:
			clear = 1
			break
if clear == 1:
	print('Yes')
else:
	print('No')


(N, M) = map(int, input().split())
A = [input() for n in range(N)]
B = [input() for m in range(M)]
ans = 'Yes'
for a in A:
	for b in B:
		if b not in a:
			ans = 'No'
print(ans)


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		window = [x[i:i + m] for x in a[j:j + m]]
		if window == b:
			print('Yes')
			quit()
print('No')


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
ans = 'No'
for i in range(n - m + 1):
	for j in range(n - m + 1):
		for k in range(m):
			if b[k] != a[k + i][j:j + m]:
				break
		else:
			ans = 'Yes'
print(ans)


(N, M) = list(map(int, input().split()))
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
R = list(range(N - M + 1))
for i in R:
	for j in R:
		for k in range(M):
			if A[j + k][i:i + M] != B[k]:
				break
		else:
			print('Yes')
			return
print('No')


(n, m) = map(int, input().split())
a = [''] * n
b = [''] * m
for i in range(n):
	a[i] = str(input())
for i in range(m):
	b[i] = str(input())
for i in range(n - m + 2):
	c = a[i:i + m]
	for j in range(n - m + 2):
		d = [e[j:j + m] for e in c]
		if b == d:
			print('Yes')
			exit()
else:
	print('No')


(n, m) = map(int, input().split())
(*a,) = [input() for _ in range(n)]
(*b,) = [input() for _ in range(m)]
print('YNeos'[all((b != [t[j:j + m] for t in a[i:i + m]] for i in range(n - m + 1) for j in range(n - m + 1)))::2])


(n, m) = list(map(int, input().split()))
ln = []
lm = []
for i in range(n):
	ln.append(input())
for i in range(m):
	lm.append(input())
lim = n - m + 1
for i in range(lim):
	for j in range(lim):
		l = 0
		for k in ln[i:i + m]:
			if k[j:j + m] != lm[l]:
				break
			l += 1
		else:
			print('Yes')
			break
	else:
		continue
	break
else:
	print('No')


(N, M) = map(int, input().split())
A = []
for i in range(N):
	a = list(input())
	A.append(a)
B = []
for i in range(M):
	b = list(input())
	B.append(b)
ans = 'No'
for i in range(N - M + 1):
	for j in range(N - M + 1):
		if A[i][j] == B[0][0]:
			count = 0
			for k in range(M):
				for l in range(M):
					if A[i + k][j + l] == B[k][l]:
						count += 1
			if count == M * M:
				ans = 'Yes'
				break
print(ans)


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
b = ''.join([input() for i in range(m)])
ans = 'No'
for i in range(n - m + 1):
	for j in range(n - m + 1):
		s = ''
		for k in range(m):
			s += a[i + k][j:j + m]
		if s == b:
			ans = 'Yes'
print(ans)


(N, M) = map(int, input().split())
A = [''] * N
B = [''] * M
for i in range(N):
	A[i] = input()
for i in range(M):
	B[i] = input()
match_cnt = 0
for i in range(N - M + 1):
	for j in range(N - M + 1):
		flag = True
		for y in range(M):
			if A[y + i][j:j + M] != B[y]:
				flag = False
		if flag:
			match_cnt += 1
if match_cnt > 0:
	print('Yes')
else:
	print('No')


(N, M) = map(int, input().split())
if N < M:
	print('No')
else:
	A = [input() for _ in range(N)]
	B = ''
	cnt = 0
	for _ in range(M):
		B += input().rstrip()
	for i in range(N - M + 1):
		if cnt == 1:
			break
		for j in range(N - M + 1):
			judge = ''
			for k in range(M):
				judge += A[i + k][j:j + M]
			if judge == B:
				cnt += 1
				break
	if cnt == 1:
		print('Yes')
	else:
		print('No')


(N, M) = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
print('Yes' if any(([A[i + k][j:j + M] for k in range(M)] == B for i in range(N - M + 1) for j in range(N - M + 1))) else 'No')


(n, m) = map(int, input().split())
A = [list(input()) for i in range(n)]
B = [list(input()) for i in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		flag = True
		for k in range(m):
			if A[k + j][i:i + m] != B[k][:]:
				flag = False
				break
		if flag:
			print('Yes')
			return
else:
	print('No')


(N, M) = map(int, input().split())
A = [[] for i in range(N)]
B = [[] for i in range(M)]
for i in range(N):
	L = list(input())
	A[i] = L
for i in range(M):
	L = list(input())
	B[i] = L
for i in range(N - M + 1):
	for j in range(N - M + 1):
		ans = 0
		for k in range(M):
			for s in range(M):
				if B[k][s] != A[i + k][j + s]:
					ans = -1
				if k == M - 1 and s == M - 1:
					if ans == 0:
						print('Yes')
						return
print('No')


(N, M) = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]
flag = False
for i in range(N - M + 1):
	for j in range(N - M + 1):
		a = [x[j:j + M] for x in A[i:i + M]]
		if a == B:
			flag = True
print('Yes' if flag == True else 'No')


(N, M) = list(map(int, input().split()))
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for y in range(N - M + 1):
	for x in range(N - M + 1):
		matched = True
		for yy in range(y, y + M):
			for xx in range(x, x + M):
				if A[yy][xx] != B[yy - y][xx - x]:
					matched = False
				if not matched:
					break
			if not matched:
				break
		if matched:
			print('Yes')
			return
print('No')


(n, m) = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]
for i in range(0, n - m + 1):
	for j in range(0, n - m + 1):
		p = [a[x][i:i + m] for x in range(j, j + m)]
		ok = 0
		for h in range(m):
			(x, y) = (p[h], b[h])
			for k in range(m):
				if x[k] != y[k]:
					ok += 1
		if ok == 0:
			print('Yes')
			return
print('No')


(n, m) = list(map(int, input().split()))
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
for (x, a) in enumerate(A):
	if x > n - m + 1:
		break
	for i in range(n - m + 1):
		if a[i:i + m] == B[0]:
			for j in range(m):
				if A[x + j][i:i + m] != B[j]:
					break
			else:
				print('Yes')
				return
print('No')


(n, m) = map(int, input().split())
a = [[] for _ in range(n)]
b = ''
c = ''
ans = 0
for i in range(n):
	a[i] = list(input())
for j in range(m):
	b += input()
for i in range(n - m + 1):
	for j in range(n - m + 1):
		for k in range(i, i + m):
			for l in range(j, j + m):
				c += a[k][l]
		if c == b:
			ans += 1
			break
		c = ''
print('Yes' if ans > 0 else 'No')


from typing import List

def answer(n: int, m: int, a: List[str], b: List[str]) -> str:
	for i in range(n - m + 1):
		for j in range(n - m + 1):
			if a[i][j:j + m] == b[0]:
				matched_lines = 1
				for k in range(1, m):
					if a[i + k][j:j + m] == b[k]:
						matched_lines += 1
					else:
						break
				if matched_lines == m:
					return 'Yes'
	return 'No'

def main():
	(n, m) = map(int, input().split())
	a = [input() for _ in range(n)]
	b = [input() for _ in range(m)]
	print(answer(n, m, a, b))

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split())
A = [list(input()) for i in range(n)]
B = [list(input()) for i in range(m)]
flag = 0
for i in range(n - m + 1):
	for j in range(n - m + 1):
		C = A[i:i + m]
		for k in range(m):
			C[k] = C[k][j:j + m]
		if C == B:
			flag = 1
print('Yes' if flag == 1 else 'No')


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
res = 'No'
c = n - m + 1
for i in range(c):
	for j in range(c):
		if list(map(lambda l: l[j:j + m], a[i:i + m])) == b:
			res = 'Yes'
print(res)


(N, M) = map(int, input().split())
A = [list(input()) for i in range(N)]
B = [list(input()) for i in range(M)]
point = 0
for nx in range(N - M + 1):
	for ny in range(N - M + 1):
		ans = [a[ny:ny + M] for a in A[nx:nx + M]]
		if ans == B:
			point += 1
if point == 0:
	print('No')
else:
	print('Yes')


(n, m) = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
ans = 'No'
for i in range(n - m + 1):
	for j in range(n - m + 1):
		S = []
		for k in range(m):
			S.append(A[i + k][j:j + m])
			if S == B:
				ans = 'Yes'
print(ans)


def f():
	(n, m) = map(int, input().split())
	a = [list(input()) for i in range(n)]
	b = [list(input()) for j in range(m)]
	for p in range(n - m + 1):
		for q in range(n - m + 1):
			cnt = 0
			for x in range(m):
				for y in range(m):
					if a[x + p][y + q] == b[x][y]:
						cnt += 1
						if cnt == m * m:
							return 'Yes'
					else:
						break
	return 'No'
print(f())


(n, m) = list(map(int, input().split()))
A = [list(input()) for _ in range(n)]
B = [list(input()) for _ in range(m)]
ok = False
for ai in range(n - m + 1):
	for aj in range(n - m + 1):
		match = True
		for bi in range(m):
			for bj in range(m):
				b = B[bi][bj]
				a = A[ai + bi][aj + bj]
				if a == b:
					continue
				else:
					match = False
					break
			if not match:
				break
		else:
			ok = True
		if ok:
			break
	if ok:
		break
print('Yes' if ok else 'No')


import math
(N, M) = list(map(int, input().split()))
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]
for i in range(0, math.ceil(N / M)):
	for j in range(0, math.ceil(N / M)):
		flag = True
		for l in range(0, M):
			for m in range(0, M):
				if A[l + i][m + j] != B[l][m]:
					flag = False
					break
		if flag == True:
			print('Yes')
			return
print('No')


(m, n) = [int(x) for x in input().split()]
a = []
b = []
for _ in range(m):
	a.append(input())
m = 0
for i in range(n):
	b.append(input())
	if b[i] in a[i]:
		m += 1
print('Yes') if m == n else print('No')


import sys
(N, M) = [int(x) for x in input().split()]
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for i in range(N - M + 1):
	for j in range(N - M + 1):
		found = True
		for _i in range(M):
			for _j in range(M):
				if A[i + _i][j + _j] != B[_i][_j]:
					found = False
					break
			if not found:
				break
		if found:
			print('Yes')
			return
print('No')


(N, M) = map(int, input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]
a = 0
for i in range(N - M + 1):
	for j in range(N - M + 1):
		for k in range(M):
			if A[j + k][i:i + M] != B[k]:
				break
		else:
			a = 1
print('Yes' if a else 'No')


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
for _ in range(m):
	b = input()
	for i in a:
		if i.find(b) >= 0:
			break
		print('No')
		exit()
print('Yes')


(x, *c) = open(0)
(n, m) = map(int, x.split())
o = n - m + 1
print('YNeos'[all((any((c[p // o + q // m][p % o + q % m] != c[n + q // m][q % m] for q in range(m * m))) for p in range(o * o)))::2])


(N, M) = [int(i) for i in input().split()]
A = [input() for i in range(N)]
B = [input() for i in range(M)]
for i in range(N - M + 1):
	for j in range(N - M + 1):
		C = [A[j + k][i:i + M] for k in range(M)]
		if B == C:
			print('Yes')
			exit()
print('No')


import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):

	def assertIO(self, input, output):
		(stdout, stdin) = (sys.stdout, sys.stdin)
		(sys.stdout, sys.stdin) = (StringIO(), StringIO(input))
		resolve()
		sys.stdout.seek(0)
		out = sys.stdout.read()[:-1]
		(sys.stdout, sys.stdin) = (stdout, stdin)
		self.assertEqual(out, output)

	def test_入力例_1(self):
		input = '3 2\n#.#\n.#.\n#.#\n#.\n.#'
		output = 'Yes'
		self.assertIO(input, output)

	def test_入力例_2(self):
		input = '4 1\n....\n....\n....\n....\n#'
		output = 'No'
		self.assertIO(input, output)

def resolve():
	(N, M) = list(map(int, input().split()))
	A = [list(input()) for _ in range(N)]
	B = [list(input()) for _ in range(M)]
	ans = 'No'
	for i in range(N - M + 1):
		for j in range(N - M + 1):
			ans = 'Yes'
			for k in range(M):
				if ans == 'No':
					break
				for l in range(M):
					if A[i + k][j + l] != B[k][l]:
						ans = 'No'
						break
			if ans == 'Yes':
				break
		if ans == 'Yes':
			break
	print(ans)

def __starting_point():
	resolve()
__starting_point()


import numpy as np
(N, M) = (int(T) for T in input().split())
A = np.zeros((N, N), dtype=bool)
B = np.zeros((M, M), dtype=bool)
for TN in range(0, N):
	A[TN, :] = [True if T == '.' else False for T in input()]
for TM in range(0, M):
	B[TM, :] = [True if T == '.' else False for T in input()]
MatchFlag = False
for TR in range(0, N - M + 1):
	for TC in range(0, N - M + 1):
		if np.sum(A[TR:TR + M, TC:TC + M] ^ B) == 0:
			MatchFlag = True
print(['No', 'Yes'][MatchFlag])


(N, M) = map(int, input().split())
A = [input() for x in range(N)]
B = [input() for x in range(M)]
c = []
for i in range(N - M + 1):
	for j in range(N - M + 1):
		a = []
		for y in range(M):
			a += [A[j + y][i:i + M]]
		c += [a]
print('Yes' if sum((1 for x in c if x == B)) > 0 else 'No')


(n, m) = map(int, input().split())
a = []
b = []
for _ in range(n):
	a.append(input())
for _ in range(m):
	b.append(input())
for i in range(n - m + 1):
	if b[i] in a[i]:
		for x in range(m - 1):
			if b[i + x] not in a[i + x]:
				print('No')
				return
		print('Yes')
		return
	else:
		print('No')
		return


(n, m, *d) = open(0).read().split()
(n, m) = (int(n), int(m))
r = range(n - m + 1)
print(['No', 'Yes'][any((d[n:] == [t[j:j + m] for t in d[i:i + m]] for i in r for j in r))])


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
ans = 'No'
for i in range(n - m + 1):
	for k in range(n - m + 1):
		if b[0] == a[i][k:k + m]:
			if sum([b[l] == a[i + l][k:k + m] for l in range(m)]) == m:
				ans = 'Yes'
				break
print(ans)


import sys
(N, M) = map(int, input().split())
A = [list(input()) for i in range(N)]
B = [list(input()) for i in range(M)]
for k in range(N - M + 1):
	for i in range(N - M + 1):
		a = [A[j + k][i:i + M] for j in range(M)]
		if a == B:
			print('Yes')
			sys.exit()
print('No')


from itertools import product as prd
(n, m) = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
c = n - m + 1
ans = [list(map(lambda l: l[j:j + m], a[i:i + m])) == b for (i, j) in prd(range(c), range(c))]
print('Yes' if any(ans) else 'No')


(N, M) = map(int, input().split())
a = [input() for w in range(N)]
b = [input() for w in range(M)]
message = 'No'
for i in range(N + M - 1):
	for j in range(N + M - 1):
		s = [t[j:j + M] for t in a[i:i + M]]
		if s == b:
			message = 'Yes'
			break
print(message)


import numpy

def main():
	(n, m) = map(int, input().split())
	a = numpy.array([list(input()) for _ in range(n)])
	b = numpy.array([list(input()) for _ in range(m)])
	for i in range(n - m + 1):
		for j in range(n - m + 1):
			if numpy.all(a[i:i + m, j:j + m] == b):
				print('Yes')
				return
	print('No')

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		x = []
		for k in range(m):
			x.append(a[i + k][j:j + m])
		if x == b:
			print('Yes')
			exit()
print('No')


(n, m) = map(int, input().split())
As = [input() for _ in range(n)]
Bs = [input() for _ in range(m)]
flag = False
for i in range(n - m + 1):
	for j in range(n - m + 1):
		if [a[j:j + m] for a in As[i:i + m]] == Bs:
			flag = True
if flag:
	print('Yes')
else:
	print('No')


(N, M) = map(int, input().split())
A = []
B = ''
for _ in range(N):
	A.append(input())
for _ in range(M):
	B += input()
for row in range(N - M + 1):
	for col in range(N - M + 1):
		tmp = ''
		for p in range(M):
			tmp += A[row + p][col:col + M]
		if tmp == B:
			print('Yes')
			return
print('No')


from itertools import product

def resolve():
	(n, m) = map(int, input().split())
	A = [input() for _ in range(n)]
	B = [input() for _ in range(m)]
	flag = any(([r[j:j + m] for r in A[i:i + m]] == B for (i, j) in product(range(n - m + 1), range(n - m + 1))))
	print('Yes' if flag else 'No')
resolve()


(n, m) = map(int, input().split())
an = [input() for _ in range(n)]
bn = [input() for _ in range(m)]
diff = n - m + 1
flag = False
for i in range(diff):
	for j in range(diff):
		if [a[j:m + j] for a in an[i:m + i]] == bn:
			flag = True
print('Yes' if flag else 'No')


(N, M) = map(int, input().split())
a = []
b = []
for i in range(N):
	a.append(input())
for i in range(M):
	b.append(input())
ans = 'No'
for i in range(N - M + 1):
	for j in range(N - M + 1):
		c = [a[k][j:j + M] for k in range(i, i + M)]
		if c == b:
			ans = 'Yes'
print(ans)


(n, m) = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
for i in range(n - m + 1):
	if B[i] in A[i]:
		for j in range(m - 1):
			if B[i + j] not in B[i + j]:
				print('No')
				exit()
		print('Yes')
		exit()
	else:
		print('No')
		exit()


import sys
(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(input()))
b = []
for i in range(m):
	b.append(list(input()))
for i in range(n - m + 1):
	for j in range(n - m + 1):
		if [c[j:j + m] for c in a[i:i + m]] == b:
			print('Yes')
			sys.exit()
print('No')


(N, M) = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
ans = 'No'
for i in range(N - M + 1):
	for j in range(N - M + 1):
		C = [A[k][i:i + M] for k in range(j, j + M)]
		if B == C:
			ans = 'Yes'
print(ans)


(n, m) = list(map(int, input().split()))
ma = []
for i in range(n):
	ma.append(input())
t = []
for i in range(m):
	t.append(input())
ans = False
for i in range(n - m + 1):
	for j in range(n - m + 1):
		for k in range(m):
			ll = ma[i + k][j:j + m]
			if ll != t[k]:
				break
		else:
			ans = True
if ans:
	print('Yes')
else:
	print('No')


(n, m) = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
ans = 'No'
for l_i in range(n - m + 1):
	for n_i in range(n - m + 1):
		sub_A = [A[l_i + m_i][n_i:n_i + m] for m_i in range(m)]
		if sub_A == B:
			ans = 'Yes'
print(ans)


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
success = 0
for i in range(n - m + 1):
	fail = 0
	for j in range(n - m + 1):
		fail = 0
		for ii in range(m):
			for jj in range(m):
				if b[ii][jj] == a[i + ii][j + jj]:
					continue
				else:
					fail = 1
					break
			if fail == 1:
				break
		else:
			success = 1
			print('Yes')
			break
	if success == 1:
		break
else:
	if fail == 1:
		print('No')


(n, m) = list(map(int, input().split()))
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]
flag = True
for i in range(n - m + 1):
	for j in range(n - m + 1):
		flag = True
		for k in range(m):
			for l in range(m):
				if b[k][l] != a[i + k][j + l]:
					flag = False
					break
		if flag:
			print('Yes')
			return
print('No')


(N, M) = list(map(int, input().split()))
A = list((list(input()) for _ in range(N)))
B = list((list(input()) for _ in range(M)))
flag = False
for i in range(0, N - M + 1):
	for j in range(0, N - M + 1):
		sub = True
		for x in range(0, M):
			for y in range(0, M):
				if A[i + x][j + y] != B[x][y]:
					sub = False
		flag = flag or sub
if flag:
	print('Yes')
else:
	print('No')


(n, m) = map(int, input().split())
A = [input() for i in range(n)]
B = [input() for i in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		s = [a[j:j + m] for a in A[i:i + m]]
		if s == B:
			print('Yes')
			exit()
print('No')


import sys
(N, M) = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for i in range(N - M + 1):
	for j in range(N - M + 1):
		new = [A[k][j:j + M] for k in range(i, i + M)]
		if new == B:
			print('Yes')
			sys.exit()
print('No')


(n, m) = map(int, input().split())
a = ['' for _ in range(n)]
b = ['' for _ in range(m)]
for i in range(n):
	ai = str(input())
	a[i] = ai
for i in range(m):
	bi = str(input())
	b[i] = bi
for i in range(n - m + 1):
	for j in range(n - m + 1):
		flag = False
		for k in range(m):
			for l in range(m):
				if a[i + k][j + l] != b[k][l]:
					flag = True
					break
			if flag:
				break
		if not flag:
			print('Yes')
			return
print('No')


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
cnt = False
for i in range(n - m + 1):
	for j in range(n - m + 1):
		t = [k[j:j + m] for k in a[i:i + m]]
		if t == b:
			cnt = True
print('Yes' if cnt else 'No')


(N, M) = map(int, input().split())
A = [input() for _ in range(N)]
B = ''.join([input() for _ in range(M)])
Z = N - M + 1
ans = [[''.join((A[i + k][j:j + M] for k in range(M))) == B for i in range(Z)] for j in range(Z)]
for b in ans:
	if True in b:
		print('Yes')
		break
else:
	print('No')


(n, m) = map(int, input().split())
a = ['' for _ in range(n)]
b = ['' for _ in range(m)]
for i in range(n):
	a[i] = str(input())
for i in range(m):
	b[i] = str(input())

def check(ini_x, ini_y):
	nonlocal n, m, a, b
	for x in range(m):
		for y in range(m):
			if a[ini_x + x][ini_y + y] != b[x][y]:
				return False
	return True
for i in range(n - m + 1):
	for j in range(n - m + 1):
		if check(i, j):
			print('Yes')
			return
print('No')


import sys
stdin = sys.stdin
ip = lambda : int(sp())
fp = lambda : float(sp())
lp = lambda : list(map(int, stdin.readline().split()))
sp = lambda : stdin.readline().rstrip()
yp = lambda : print('Yes')
np = lambda : print('No')
(n, m) = lp()
ans = []
for _ in range(n):
	s = list(sp())
	ans.append(s)
next = []
for _ in range(m):
	p = list(sp())
	next.append(p)
ok = 0
count = 0
for x in range(n - m + 1):
	for y in range(n - m + 1):
		ch = 0
		for e in range(m):
			for f in range(m):
				if ans[x + e][y + f] == next[e][f]:
					ch += 1
				if ch == m * m:
					ok += 1
if ok == 0:
	print('No')
else:
	print('Yes')


(N, M) = map(int, input().split())
A = [input().rstrip() for i in range(N)]
B = [input().rstrip() for i in range(M)]
for i in range(N - M + 1):
	for j in range(N - M + 1):
		f = True
		for k in range(M):
			if A[i + k][j:j + M] != B[k]:
				f = False
				break
		if f:
			print('Yes')
			exit()
print('No')


(n, m) = map(int, input().split())
a = [list(input()) for i in range(n)]
b = [list(input()) for i in range(m)]
ans = 0
for i in range(n - m + 1):
	for j in range(n - m + 1):
		a2 = [k[j:j + m] for k in a[i:i + m]]
		if a2 == b:
			ans = 1
if ans == 1:
	print('Yes')
else:
	print('No')


(N, M) = list(map(int, input().split()))
A = []
for _ in range(N):
	a = input()
	A.append(a)
B = []
for _ in range(M):
	b = input()
	B.append(b)
idx = [0, 0]
while True:
	if idx[0] == N - 1 and idx[1] == N - 1:
		break
	if A[idx[0]][idx[1]] == B[0][0]:
		check = False
		for i in range(M):
			for j in range(M):
				if 0 <= idx[0] + i < N and 0 <= idx[1] + j < N:
					if A[idx[0] + i][idx[1] + j] != B[i][j]:
						check = True
						break
				else:
					check = True
					break
			if check:
				break
		if not check:
			print('Yes')
			return
	if idx[1] < N - 1:
		idx[1] += 1
		continue
	else:
		idx[0] += 1
		idx[1] = 1
		continue
if A[-1][-1] == B[0][0] and M == 1:
	print('Yes')
	return
print('No')


(N, M) = map(int, input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]
for i in range(N - M + 1):
	for j in range(len(A[0]) - len(B[0]) + 1):
		l = []
		for k in range(M):
			l.append(A[i + k][j:j + M])
		if l == B:
			print('Yes')
			exit()
print('No')


(N, M) = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
import sys
for a in A:
	for b in B:
		if b not in a:
			print('No')
			sys.exit()
print('Yes')


(N, M) = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = ''
for _ in range(M):
	B += input()
ans = 'No'
for i in range(N - M + 1):
	for j in range(N - M + 1):
		sbstr = ''
		for k in range(M):
			sbstr += ''.join(A[i + k][j:j + M])
		if B == sbstr:
			ans = 'Yes'
print(ans)


import numpy as np
(N, M) = map(int, input().split())
A = np.array([list(str(input())) for i in range(N)])
B = np.array([list(str(input())) for j in range(M)])
ans = 'No'
for i in range(N - M + 1):
	for j in range(N - M + 1):
		x = [s[j:M + j] for s in A[i:M + i]]
		if np.count_nonzero((x == B) == 0) == 0:
			ans = 'Yes'
print(ans)


(n, m) = map(int, input().split())
a = []
b = []
ans = 0
for i in range(n):
	a.append(list(input()))
for i in range(m):
	b.append(list(input()))
for i in range(n - m + 1):
	for j in range(n - m + 1):
		cnt = 0
		for s in range(m):
			for t in range(m):
				if b[s][t] == a[s + i][t + j]:
					cnt += 1
		if cnt == m * m:
			ans = 1
if ans == 0:
	print('No')
else:
	print('Yes')


(N, M) = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
cnt = 0
tmp = []
for a in A:
	for b in B:
		if tmp != B:
			if b in a:
				tmp.append(b)
		else:
			break
if tmp == B:
	print('Yes')
else:
	print('No')


I = input
(n, m) = map(int, I().split())
a = [I() for _ in [0] * n]
b = [I() for _ in [0] * m]
r = n - m + 1
print('YNeos'[sum((sum((b == [t[j:j + m] for t in a[i:i + m]] for j in range(r))) for i in range(r))) < 1::2])


(n, m) = list(map(int, input().split()))
al = [input() for i in range(n)]
bl = [input() for i in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		for k in range(m):
			if al[i + k][j:j + m] != bl[k]:
				break
		else:
			print('Yes')
			exit()
print('No')


import sys
(n, m) = map(int, input().split())
la = [input() for _ in range(n)]
lb = [input() for _ in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		cnt = 0
		for k in range(m):
			for l in range(m):
				if la[i + k][j + l] == lb[k][l]:
					cnt += 1
		if cnt == m ** 2:
			print('Yes')
			return
print('No')


import numpy as np
(n, m) = map(int, input().split())
aa = [list(input()) for i in range(n)]
bb = [list(input()) for i in range(m)]
a = np.array(aa)
b = np.array(bb)
for i in range(n - m + 1):
	for j in range(n - m + 1):
		if (a[i:i + m, j:j + m] == b).all():
			print('Yes')
			return
print('No')


(n, m) = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
ok = 0
for i in range(n - m + 1):
	for k in range(n - m + 1):
		if B[0] == A[i][k:k + m]:
			for j in range(i, i + m):
				if B[j - i] != A[j][k:k + m]:
					break
			else:
				ok = 1
print('Yes' if ok == 1 else 'No')


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
ans = 'No'
for i in range(n - m + 1):
	for j in range(n - m + 1):
		C = [a[i + k][j:j + m] for k in range(m)]
		if C == b:
			ans = 'Yes'
print(ans)


(N, M) = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [input() for _ in range(M)]
for i in range(M):
	for j in range(N - M + 1):
		str_n = ''.join(A[i][j:j + M])
		if str_n == B[i]:
			break
	else:
		print('No')
		exit()
else:
	print('Yes')


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		ans = True
		for k in range(m):
			if b[k] != a[i + k][j:j + m]:
				ans = False
		if ans:
			print('Yes')
			return
print('No')


(N, M) = map(int, input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]
Match = False
for i in range(N - M + 1):
	for j in range(N - M + 1):
		Compare = [A[k][j:j + M] for k in range(i, i + M)]
		if Compare == B:
			Match = True
print('Yes' if Match else 'No')


import sys
(n, m) = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		A = [a[s][i:i + m] for s in range(j, j + m)]
		if A == b:
			print('Yes')
			sys.exit()
print('No')


(N, M) = map(int, input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]
judge = any(([line[j:j + M] for line in A[i:i + M]] == B for i in range(N - M + 1) for j in range(N - M + 1)))
print('Yes' if judge else 'No')


(N, M) = map(int, input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]
for i in range(N - M + 1):
	for j in range(N - M + 1):
		ans = 1
		for k in range(M):
			if B[k] != A[i + k][j:j + M]:
				ans = 0
		if ans == 1:
			print('Yes')
			return
print('No')


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for h in range(n - m + 1):
	for w in range(n - m + 1):
		if all((a[h + y][w + x] == b[y][x] for y in range(m) for x in range(m))):
			print('Yes')
			exit()
print('No')


(N, M) = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for i in range(N - M + 1):
	for j in range(N - M + 1):
		t = [k[j:j + M] for k in A[i:i + M]]
		if t == B:
			print('Yes')
			exit()
print('No')


(n, m, *a) = open(0).read().split()
(n, m) = (int(n), int(m))
r = range(n - m + 1)
print('YNeos'[all((a[n:] != [t[j:j + m] for t in a[i:i + m]] for i in r for j in r))::2])


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		if b[0][0] == a[i][j]:
			cnt = 0
			for x in range(m):
				flag = True
				if flag == False:
					break
				for y in range(m):
					if b[x][y] == a[i + x][j + y]:
						cnt += 1
						pass
					else:
						flag = False
						break
					if cnt == m ** 2:
						print('Yes')
						return
print('No')


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for j in range(m)]
for i in range(n):
	for j in range(n - m + 1):
		tf = 0
		if a[i][j:j + m] == b[0] and i + m <= n:
			tf = 1
			for k in range(i + 1, i + m):
				if a[k][j:j + m] != b[k - i]:
					tf = 0
		if tf:
			print('Yes')
			return
else:
	print('No')


from itertools import product
(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for (i, j) in product(range(n - m + 1), repeat=2):
	if all((a[i + k][j:j + m] == b[k] for k in range(m))):
		print('Yes')
		break
else:
	print('No')


(N, M) = map(int, input().strip().split(' '))
a = []
b = []
for i in range(N):
	a.append(input())
N = 0
for i in range(M):
	b.append(input())
	if b[i] in a[i]:
		N += 1
if N == M:
	print('Yes')
else:
	print('No')


(n, m) = map(int, input().split())
alist = [input() for _ in range(n)]
blist = [input() for _ in range(m)]

def match(i, j):
	for di in range(m):
		for dj in range(m):
			if alist[i + di][j + dj] != blist[di][dj]:
				return False
	return True
for i in range(n - m + 1):
	for j in range(n - m + 1):
		if match(i, j):
			print('Yes')
			return
print('No')


(n, m) = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
for h in range(n - m + 1):
	for w in range(n - m + 1):
		wi = [a[w:w + m] for a in A[h:h + m]]
		if wi == B:
			print('Yes')
			exit()
print('No')


(N, M) = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]
check = False
for i in range(N - M + 1):
	for j in range(N - M + 1):
		if A[i][j:j + M] == B[0]:
			flag = True
			for k in range(1, M):
				if A[i + k][j:j + M] != B[k]:
					flag = False
			if flag:
				check = True
print('Yes' if check else 'No')


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		c = True
		for k in range(m):
			if a[i + k][j:j + m] != b[k]:
				c = False
		if c:
			print('Yes')
			exit()
print('No')


(N, M) = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for i in range(N - M + 1):
	for j in range(N - M + 1):
		flag = True
		AA = [a[j:j + M] for a in A[i:i + M]]
		for (a, b) in zip(AA, B):
			if a != b:
				flag = False
		if flag:
			print('Yes')
			return
print('No')


(n, m) = map(int, input().split())
f = lambda k: [input() for _ in range(k)]
(ln, lm) = (f(n), f(m))
for i in range(n - m + 1):
	for j in range(n - m + 1):
		lk = [s[j:j + m] for s in ln[i:i + m]]
		if lk == lm:
			print('Yes')
			break
	else:
		continue
	break
else:
	print('No')


(N, M) = map(int, input().split())
A = []
B = []
for i in range(N):
	A.append(input())
for i in range(M):
	B.append(input())
ans = True
for i in range(M):
	if B[i] not in A[i]:
		ans = False
		break
print('Yes' if ans == True else 'No')


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
res = False
for i in range(n - m + 1):
	for j in range(n - m + 1):
		t = [r[j:j + m] for r in a[i:i + m]]
		res |= t == b
print('Yes' if res else 'No')


def main():
	(n, m) = list(map(int, input().split()))
	(a, b) = ([], [])
	for i in range(n):
		a.append(input())
	for i in range(m):
		b.append(input())
	for i in range(n - m + 1):
		for j in range(n - m + 1):
			a_ = []
			for k in range(m):
				a_.append(a[i + k][j:j + m])
			if a_ == b:
				print('Yes')
				return
	print('No')

def __starting_point():
	main()
__starting_point()


import itertools
(N, M) = [int(_) for _ in input().split()]
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for (i, j) in itertools.product(range(N - M + 1), repeat=2):
	if [_[j:j + M] for _ in A[i:i + M]] == B:
		print('Yes')
		exit()
print('No')


import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float('inf')
IINF = 10 ** 18

def solve():
	(n, m) = list(map(int, stdin.readline().rstrip().split()))
	a = [stdin.readline().rstrip() for _ in range(n)]
	b = [stdin.readline().rstrip() for _ in range(m)]
	for i in range(n - m + 1):
		for j in range(n - m + 1):
			flag = True
			for h in range(m):
				if a[i + h][j:j + m] != b[h]:
					flag = False
					break
			if flag == True:
				print('Yes')
				return
	print('No')

def __starting_point():
	solve()
__starting_point()


(n, m) = map(int, input().split())
list_A = list((input() for i in range(n)))
list_B = list((input() for i in range(m)))
k = 'No'
for i in range(n - m + 1):
	for t in range(n - m + 1):
		if all((list_A[v + i][t:t + m] == list_B[v] for v in range(m))):
			k = 'Yes'
			break
print(k)


(N, M) = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for i in range(N - M + 1):
	for j in range(N - M + 1):
		flg = True
		for k in range(M):
			for l in range(M):
				flg = flg & (B[k][l] == A[i + k][j + l])
		if flg:
			ans = 'Yes'
			print(ans)
			return
ans = 'No'
print(ans)


def solve(n, m, original, temp):

	def judge(sy, sx):
		for i in range(m):
			for j in range(m):
				if original[sy + i][sx + j] != temp[i][j]:
					return False
		return True
	sy = 0
	while sy + m - 1 < n:
		sx = 0
		while sx + m - 1 < n:
			if judge(sy, sx):
				return True
			sx += 1
		sy += 1
	return False

def main():
	(N, M) = list(map(int, input().split()))
	a = [input() for _ in range(N)]
	b = [input() for _ in range(M)]
	print('Yes' if solve(N, M, a, b) else 'No')
	return

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
mon = ([row[j:j + m] for row in a[i:i + m]] for i in range(n - m + 1) for j in range(n - m + 1))
print('Yes' if any((c == b for c in mon)) else 'No')


(n, m) = list(map(int, input().split()))
a = [input() for i in range(n)]
b = [input() for i in range(m)]
ans = 'Yes'
for i in a:
	for j in b:
		if j not in i:
			ans = 'No'
print(ans)


(n, m) = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
ans = 'No'
flag = False
for i in range(n - m + 1):
	for j in range(n - m + 1):
		C = [A[i + k][j:j + m] for k in range(m)]
		if B == C:
			ans = 'Yes'
print(ans)


(n, m) = map(int, input().split())
A = [input() for i in range(n)]
B = [input() for i in range(m)]
ans = 0
for i in range(n - m + 1):
	for j in range(n - m + 1):
		if [a[j:j + m] for a in A[i:i + m]] == B:
			ans = 1
if ans == 1:
	print('Yes')
else:
	print('No')


def main():
	(n, m) = list(map(int, input().split()))
	A = [input() for i in range(n)]
	B = [input() for i in range(m)]
	for i in range(n):
		C = []
		p = A[i].find(B[0])
		if p != -1:
			for j in range(m):
				if i + j < n and p + len(B[0]) <= n:
					C.append(A[i + j][p:p + len(B[0])])
			if C == B:
				break
	print('Yes' if C == B else 'No')

def __starting_point():
	main()
__starting_point()


import math
from math import gcd, pi, sqrt
INF = float('inf')
import sys
sys.setrecursionlimit(10 ** 6)
import itertools
from collections import Counter, deque

def i_input():
	return int(input())

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

def i_list():
	return list(i_map())

def i_row(N):
	return [i_input() for _ in range(N)]

def i_row_list(N):
	return [i_list() for _ in range(N)]

def s_input():
	return input()

def s_map():
	return input().split()

def s_list():
	return list(s_map())

def s_row(N):
	return [s_input for _ in range(N)]

def s_row_str(N):
	return [s_list() for _ in range(N)]

def s_row_list(N):
	return [list(s_input()) for _ in range(N)]
import string

def main():
	(N, M) = i_map()
	a = [s_input() for _ in range(N)]
	b = [s_input() for _ in range(M)]
	for i in range(N - M + 1):
		for j in range(N - M + 1):
			flg = True
			for x in range(M):
				for y in range(M):
					if b[x][y] != a[i + x][j + y]:
						flg = False
						break
				if flg == False:
					break
			if flg == True:
				print('Yes')
				return
	print('No')

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
x = n - ~-m
C = 0
for i in range(x):
	for j in range(x):
		c = 0
		for k in range(m):
			if a[i + k][j:j + m] == b[k]:
				c += 1
		if c == m:
			C += 1
print('YNeos'[C < 1::2])


(N, M) = map(int, input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]
ans = 'Yes'
for i in A:
	for j in B:
		if j not in i:
			ans = 'No'
print(ans)


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for j in range(m)]
res = 'No'
if m == 1:
	for i in a:
		if b[0] in i:
			res = 'Yes'
else:
	for k in range(n - m + 1):
		if b[0] in a[k]:
			for l in range(n - m + 1):
				if b[0] == a[k][l:m + l]:
					cnt = 0
					for o in range(m - 1):
						if b[o + 1] == a[k + o + 1][l:m + l]:
							cnt += 1
					if cnt == m - 1:
						res = 'Yes'
print(res)


(N, M) = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
ans = 'No'
for i in range(N - M + 1):
	for j in range(N - M + 1):
		flag = True
		for k in range(M):
			for l in range(M):
				if A[i + k][j + l] != B[k][l]:
					flag = False
					break
		if flag:
			ans = 'Yes'
			break
print(ans)


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
ans = 0
for i in range(n - m + 1):
	for j in range(n - m + 1):
		if [a[j:j + m] for a in a[i:i + m]] == b:
			ans = 1
print('Yes' if ans == 1 else 'No')


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
flag = 0
for i in range(n - m + 1):
	for j in range(n - m + 1):
		c = [x[j:j + m] for x in a[i:i + m]]
		if c == b:
			flag = 1
			break
print('Yes') if flag == 1 else print('No')


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
ans = 0
for i in range(n - m + 1):
	for s in range(n - m + 1):
		t = [k[s:s + m] for k in a[i:i + m]]
		if t == b:
			ans = 1
print('Yes') if ans == 1 else print('No')


(N, M) = map(int, input().split(' '))
A = [input() for x in range(N)]
B = [input() for x in range(M)]
ans = 'No'
for h in range(0, N - M + 1):
	for w in range(0, N - M + 1):
		if sum([B[i] != A[i + h][w:w + M] for i in range(M)]) == 0:
			ans = 'Yes'
			break
	if ans == 'Yes':
		break
print(ans)


(n, m) = map(int, input().split())
A = [input() for i in range(n)]
B = [input() for j in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		if A[i][j:j + m] == B[0]:
			if all((A[i + k][j:j + m] == B[k] for k in range(1, m))):
				print('Yes')
				exit()
print('No')


import numpy
(n, m) = map(int, input().split())
a = numpy.zeros([n, n], dtype=int)
b = numpy.zeros([m, m], dtype=int)
for i in range(n):
	s = input()
	for j in range(n):
		if s[j] == '#':
			a[i, j] = 1
for i in range(m):
	s = input()
	for j in range(m):
		if s[j] == '#':
			b[i, j] = 1
for i in range(n - m + 1):
	for j in range(n - m + 1):
		if numpy.all(a[i:i + m, j:j + m] == b):
			print('Yes')
			return
print('No')


(N, M) = map(int, input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]
for i in range(N - M + 1):
	for j in range(N - M + 1):
		t = True
		for k in range(M):
			if B[k] != A[i + k][j:j + M]:
				t = False
		if t:
			print('Yes')
			return
print('No')


(N, M) = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
print('YNeos'[all((any((t != s[j:j + M] for (s, t) in zip(A[i:], B))) for i in range(N - M + 1) for j in range(N - M + 1)))::2])


(N, M) = map(int, input().split())
A = [''] * N
B = [''] * M
for i in range(N):
	A[i] = input()
for i in range(M):
	B[i] = input()
A_tmp = [''] * M
for i in range(N - M + 1):
	for j in range(N - M + 1):
		for k in range(M):
			A_tmp[k] = A[j + k][i:i + M]
		if A_tmp == B:
			print('Yes')
			exit(0)
print('No')


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
r = range(n - m + 1)
for i in r:
	for j in r:
		for k in range(m):
			if a[i + k][j:j + m] != b[k]:
				break
		else:
			print('Yes')
			exit()
print('No')


import sys, math
from itertools import combinations as c, product as p
from collections import deque
sys.setrecursionlimit(10 ** 9)

def si():
	return input()

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

def fi():
	return float(input())

def lstr():
	return input().split()

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

def lint_dec():
	return list(map(lambda x: int(x) - 1, input().split()))

def lnstr(n):
	return [input() for _ in range(n)]

def lnint(n):
	return [int(input()) for _ in range(n)]

def lint_list(n):
	return [lint() for _ in range(n)]
(N, M) = lint()
A = lnstr(N)
B = lnstr(M)
FLG = False
for i in range(N - M + 1):
	for k in range(N - M + 1):
		if [A[j + k][i:i + M] for j in range(M)] == B:
			FLG = True
			break
	if FLG:
		break
print('Yes' if FLG else 'No')


import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

def I():
	return int(input())

def F():
	return float(input())

def SS():
	return input()

def LI():
	return [int(x) for x in input().split()]

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

def LSS():
	return input().split()

def resolve():
	(N, M) = LI()
	A = [SS() for _ in range(N)]
	B = [SS() for _ in range(M)]
	is_ok = False
	for (i, j) in itertools.product(list(range(N - M + 1)), repeat=2):
		tmp = True
		for k in range(M):
			if B[k] != A[i + k][j:j + M]:
				tmp = False
				break
		if tmp:
			is_ok = True
			break
	if is_ok:
		print('Yes')
	else:
		print('No')

def __starting_point():
	resolve()
__starting_point()


import itertools
(n, m) = [int(i) for i in input().split()]
a = [input() for i in range(n)]
b = [input() for i in range(m)]
ans = 0
for (i, j) in itertools.product(range(n - m + 1), repeat=2):
	if b == [a[i + _][j:j + m] for _ in range(m)]:
		ans = 1
print(['No', 'Yes'][ans])


(N, M) = [int(a) for a in input().split()]
A = []
B = []
for i in range(N):
	A.append(input())
for i in range(M):
	B.append(input())
wa = len(A[0])
wb = len(B[0])
matched = False
for i1 in range(N - M + 1):
	for j1 in range(wa - wb + 1):
		cnt = 0
		for i2 in range(M):
			if B[i2] == A[i1 + i2][j1:j1 + wb]:
				cnt += 1
		if cnt == M:
			matched = True
			break
if matched:
	print('Yes')
else:
	print('No')


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
res = True
for i in range(len(b)):
	if b[i] not in a[i]:
		res = False
		break
print('Yes' if res else 'No')


(n, m) = map(int, input().split())
s1 = [input() for _ in range(n)]
s2 = [input() for _ in range(m)]
ans = 'No'
for i in range(n - m + 1):
	for j in range(n - m + 1):
		flg = 0
		for k in range(m):
			if s1[j + k][i:i + m] == s2[k]:
				flg += 1
		if flg == m:
			ans = 'Yes'
print(ans)


(N, M) = map(int, input().split())
A = ''
B = ''
for i in range(N):
	A += input()
for i in range(M):
	if not i % 2 == 0:
		B += input()[::-1]
	else:
		B += input()
if B in A:
	print('Yes')
else:
	print('No')


(n, m) = [int(x) for x in input().split()]
A = [input() for i in range(n)]
B = [input() for i in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		if [a[j:j + m] for a in A[i:i + m]] == B:
			print('Yes')
			break
	else:
		continue
	break
else:
	print('No')


(a, b) = map(int, input().split())
lineA = [input() for i in range(a)]
lineB = [input() for i in range(b)]
count = 0
for i in range(b):
	if lineB[i] in lineA[i]:
		count += 1
if count == b:
	print('Yes')
else:
	print('No')


(n, m) = map(int, input().split())
l = [input() for i in range(n)]
ml = [input() for i in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		for h in range(m):
			if ml[h] != l[i + h][j:j + m]:
				break
		else:
			print('Yes')
			exit()
print('No')


(n, m) = map(int, input().split())
lia = [input() for i in range(n)]
lib = [input() for i in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		for k in range(m):
			if lia[i + k][j:j + m] != lib[k]:
				break
		else:
			print('Yes')
			exit()
print('No')


(n, m) = map(int, input().split())
a = [input() for _ in [0] * n]
b = [input() for _ in [0] * m]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		f = 1
		for s in range(m):
			for t in range(m):
				if a[i + s][j + t] != b[s][t]:
					f = 0
		if f:
			break
	if f:
		break
print(['No', 'Yes'][f])


(n, m) = list(map(int, input().split()))
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
flag = False
for i in range(n - m + 1):
	for s in range(n - m + 1):
		if b[0] == a[i][s:s + m]:
			index = s
			cnt = 1
			for j in range(1, m):
				if not a[i + j][index:index + m] == b[j]:
					break
				cnt += 1
			if cnt == m:
				flag = True
				break
print('Yes' if flag else 'No')


import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque, Counter
from decimal import Decimal
import functools

def v():
	return input()

def k():
	return int(input())

def S():
	return input().split()

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

def X():
	return list(input())

def L():
	return list(input().split())

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

def lcm(a, b):
	return a * b // math.gcd(a, b)
sys.setrecursionlimit(10 ** 9)
mod = 10 ** 9 + 7
cnt = 0
ans = 0
inf = float('inf')
al = 'abcdefghijklmnopqrstuvwxyz'
AL = al.upper()
(n, m) = I()
a = []
b = []
for _ in range(n):
	a += [list(input())]
for _ in range(m):
	b += [list(input())]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		if [k[j:m + j] for k in a[i:m + i]] == b:
			print('Yes')
			return
print('No')


import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce
rr = lambda : sys.stdin.readline().rstrip()
rs = lambda : sys.stdin.readline().split()
ri = lambda : int(sys.stdin.readline())
rm = lambda : list(map(int, sys.stdin.readline().split()))
rl = lambda : list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10 ** 9 + 7
(n, m) = rm()
a = [rr() for _ in range(n)]
b = [rr() for _ in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		c = [s[j:j + m] for s in a[i:i + m]]
		if c == b:
			print('Yes')
			return
print('No')


(n, m) = map(int, input().split())
ary_n = [input() for _ in range(n)]
s = ''.join([input() for _ in range(m)])
ret = 'No'
for x in range(n - m + 1):
	tmp = ''
	for y in range(n):
		tmp += ary_n[y][x:x + m]
	if tmp.find(s) >= 0:
		ret = 'Yes'
		break
print(ret)


(n, m) = list(map(int, input().split()))
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
ans = False
for y in range(n - m + 1):
	for x in range(n - m + 1):
		sol = True
		for h in range(m):
			if a[y + h][x:x + m] != b[h]:
				sol = False
				break
		if sol:
			ans = True
			break
	if ans:
		break
print('Yes' if ans else 'No')


(N, M) = list(map(int, input().split()))
A = []
B = []
for i in range(N):
	A.append(input())
for i in range(M):
	B.append(input())
for i in range(N - M + 1):
	if B[0] in A[i]:
		k = A[i].index(B[0])
		points = 1
		for j in range(1, M):
			if B[j] == A[i + j][k:k + M]:
				points += 1
		if points == M:
			print('Yes')
			return
print('No')


(n, m) = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
for r in range(n - m + 1):
	for c in range(n - m + 1):
		X = []
		for a in A[r:r + m]:
			X.append(a[c:c + m])
		if X == B:
			print('Yes')
			exit()
print('No')


(N, M) = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for i in range(N - M + 1):
	for j in range(N - M + 1):
		if all([A[i + x][j + y] == B[x][y] for x in range(M) for y in range(M)]):
			print('Yes')
			exit()
print('No')


(n, m) = map(int, input().split())
p = ''
c = ''
for i in range(n):
	p = p + input()
for i in range(m):
	if not i % 2 == 0:
		c = c + input()[::-1]
	else:
		c = c + input()
if c in p:
	print('Yes')
else:
	print('No')


(n, m) = map(int, input().split())
a = [[j for j in input()] for i in range(n)]
b = [[j for j in input()] for i in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		if all((k[j:j + m] == b[bi] for (bi, k) in enumerate(a[i:i + m]))):
			print('Yes')
			quit()
print('No')


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		tnp = 0
		for k in range(m):
			for l in range(m):
				if a[i + k][j + l] != b[k][l]:
					tnp += 1
		if tnp == 0:
			print('Yes')
			return
print('No')


(N, M) = map(int, input().split())
A = []
B = []
for _ in range(N):
	A.append(input())
for _ in range(M):
	B.append(input())
for (a, b) in zip(A, B):
	if b in a:
		flag = True
	else:
		flag = False
		break
if flag:
	print('Yes')
else:
	print('No')


lst = input().split()
N = int(lst[0])
M = int(lst[1])
A = []
B = []
for i in range(N):
	A.append(input())
for i in range(M):
	B.append(input())
if A == B:
	print('Yes')
	return
for x in range(N - M):
	for y in range(N - M):
		count = 1
		for i in range(M):
			if A[y + i][x:x + M] != B[i]:
				count = 0
		if count == 1:
			print('Yes')
			return
print('No')


(N, M) = map(int, input().split())
A = []
B = []
for i in range(N):
	A.append(input())
for i in range(M):
	B.append(input())
for h in range(N - M + 1):
	for w in range(N - M + 1):
		if list(map(lambda x: x[w:w + M], A[h:h + M])) == B:
			print('Yes')
			exit()
print('No')


(N, M) = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

def match(x, y):
	return all((a[x:x + M] == b for (a, b) in zip(A[y:], B)))
print(any((match(x, y) for y in range(N - M + 1) for x in range(N - M + 1))) and 'Yes' or 'No')


(n, m) = map(int, input().split())
A = []
B = []
for i in range(n):
	A.append(input())
for i in range(m):
	B.append(input())
ok = 0
for i in range(n - m + 1):
	for j in range(n - m + 1):
		from_n = [l[j:j + m] for l in A[i:i + m]]
		ok += from_n == B
print('Yes' if ok > 0 else 'No')


(n, m) = map(int, input().split(' '))
a = [list(input()) for i in range(n)]
b = [list(input()) for i in range(m)]
ch = m ** 2
for i in range(n - m + 1):
	for j in range(n - m + 1):
		if a[i][j] == b[0][0]:
			count = 0
			for k in range(m):
				for l in range(m):
					if a[i + k][j + l] == b[k][l]:
						count += 1
			if count == ch:
				print('Yes')
				break
	else:
		continue
	break
else:
	print('No')


(N, M) = map(int, input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]
for i in range(N - M + 1):
	pos = -1
	for j in range(A[i].count(B[0])):
		pos = A[i].find(B[0], pos + 1)
		for k in range(1, M):
			if A[i + k].find(B[k], pos) != pos:
				break
		else:
			print('Yes')
			break
	else:
		continue
	break
else:
	print('No')


import sys
(N, M) = map(int, input().split())
A = [sys.stdin.readline().strip() for _ in range(N)]
B = [sys.stdin.readline().strip() for _ in range(M)]
for i in range(N - M + 1):
	for j in range(N - M + 1):
		As = [x[i:i + M] for x in A[j:j + M]]
		if B == As:
			print('Yes')
			sys.exit()
print('No')


(N, M) = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
b = any((all((A[i + k][j + l] == B[k][l] for k in range(M) for l in range(M))) for i in range(N - M + 1) for j in range(N - M + 1)))
print('YNeos'[not b::2])


(N, M) = map(int, input().split())
A = [input() for i in range(N)]
B = [input() for j in range(M)]
ans = True
for k in range(len(B)):
	if B[k] not in A[k]:
		ans = False
		break
print('Yes' if ans == True else 'No')


import sys
(n, m) = map(int, input().split())
a_list = sum([input().split() for i in range(n)], [])
b_list = sum([input().split() for i in range(m)], [])
for b in b_list:
	for a in a_list:
		if b not in a:
			print('No')
			sys.exit()
print('Yes')


(n, m) = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]
eq = False
find = False
for i in range(n - m + 1):
	for j in range(n - m + 1):
		for p in range(m):
			for q in range(m):
				if a[p + i][q + j] == b[p][q]:
					eq = True
				else:
					eq = False
					break
			if not eq:
				break
		if eq:
			find = True
			break
	if find:
		break
if find:
	print('Yes')
else:
	print('No')


(n, m) = map(int, input().split())
(a, b) = ([], [])
for i in range(n):
	a.append(input())
for i in range(m):
	b.append(input())
ans = False
for i in range(n - m + 1):
	for j in range(n - m + 1):
		flag = True
		for k in range(m):
			if a[i + k][j:j + m] != b[k]:
				flag = False
		if flag:
			ans = True
if ans:
	print('Yes')
else:
	print('No')


def main():
	(n, m) = map(int, input().split())
	a_l = [input() for i in range(n)]
	b_l = [input() for i in range(m)]
	for i in range(n - m + 1):
		for j in range(n - m + 1):
			ans = 'Yes'
			for k in range(m):
				for l in range(m):
					if a_l[i + k][j + l] != b_l[k][l]:
						ans = 'No'
			else:
				if ans == 'Yes':
					print(ans)
					return
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, M) = map(int, input().split())
a = [input() for i in range(N)]
b = [input() for i in range(M)]
ans = 0
for i in range(N - M + 1):
	for j in range(N - M + 1):
		t = [k[j:j + M] for k in a[i:i + M]]
		if t == b:
			print('Yes')
			exit()
print('No')


(n, m) = map(int, input().split())
a_lst = [str(input()) for _ in range(n)]
b_lst = [str(input()) for _ in range(m)]
flag = False
for i in range(n - m + 1):
	for j in range(n - m + 1):
		count = 0
		if a_lst[i][j] == b_lst[0][0]:
			for k in range(m):
				for l in range(m):
					if a_lst[i + k][j + l] == b_lst[k][l]:
						count += 1
			if count == m ** 2:
				flag = True
if flag:
	print('Yes')
else:
	print('No')


(n, m) = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]

def dfs(y, x):
	for Y in range(m):
		for X in range(m):
			if A[y + Y][x + X] != B[Y][X]:
				return False
	return True
ans = 'No'
for y in range(n - m + 1):
	for x in range(n - m + 1):
		if A[y][x] == B[0][0]:
			if dfs(y, x):
				ans = 'Yes'
				break
	else:
		continue
	break
print(ans)


(n, m) = map(int, input().split())
np = [input() for _ in range(n)]
mp = [input() for _ in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		f = True
		for k in range(m):
			if np[i + k][j:j + m] != mp[k]:
				f = False
		if f:
			print('Yes')
			exit(0)
else:
	print('No')


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n - m + 1):
	c = a[i].find(b[0])
	if c != -1:
		for k in range(m - 1):
			if a[i + k + 1][c:c + m] != b[k + 1]:
				break
		else:
			print('Yes')
			break
else:
	print('No')


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
f = 0
for i in range(n - m + 1):
	for j in range(n - m + 1):
		t = [k[j:j + m] for k in a[i:i + m]]
		if t == b:
			f = 1
print('Yes' if f else 'No')


(n, m) = map(int, input().split())
N = [input() for _ in range(n)]
M = [input() for _ in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		N_ = []
		for k in range(m):
			N_.append(N[i + k][j:j + m])
		if N_ == M:
			print('Yes')
			exit()
print('No')


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
ans = 'No'
for i in range(n - m + 2):
	c = a[i:i + m]
	for j in range(n - m + 2):
		d = [e[j:j + m] for e in c]
		if b == d:
			ans = 'Yes'
print(ans)


(N, M) = map(int, input().split())
(A, B) = ([''] * N, [''] * M)
for i in range(N):
	A[i] = input()
for i in range(M):
	B[i] = input()

def check(x, y):
	if x + M > N or y + M > N:
		return False
	for i in range(M):
		for j in range(M):
			if A[x + i][y + j] != B[i][j]:
				return False
	return True
for i in range(N):
	for j in range(N):
		if check(i, j):
			print('Yes')
			return
print('No')


(N, M) = map(int, input().split())
A = [input() for i in range(N)]
B = ''.join([input() for i in range(M)])
f = 0
for i in range(N - M + 1):
	for j in range(N - M + 1):
		if ''.join([A[l][j:j + M] for l in range(i, i + M)]) == B:
			f = 1
print(['No', 'Yes'][f])


def main():
	(n, m) = list(map(int, input().split()))
	a = ['' for i in range(n)]
	b = ['' for i in range(m)]
	for i in range(n):
		a[i] = input()
	for i in range(m):
		b[i] = input()
	for i1 in range(n - m + 1):
		for i2 in range(n - m + 1):
			fl = True
			for j in range(m):
				for k in range(m):
					if a[i1 + j][i2 + k] != b[j][k]:
						fl = False
			if fl:
				print('Yes')
				return
	print('No')

def __starting_point():
	main()
__starting_point()


import re
(n, m) = map(int, input().split())
a = ' '.join([input().replace('.', 'o') for i in [0] * n])
b = ('.' * (n - m + 1)).join([input().replace('.', 'o') for i in [0] * m])
if re.search(b, a):
	print('Yes')
else:
	print('No')


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
for i in range(n - m + 1):
	for l in range(n - m + 1):
		ok = True
		for j in range(m):
			for k in range(m):
				if b[j][k] != a[i + j][l + k]:
					ok = False
		if ok:
			print('Yes')
			exit()
print('No')


(N, M) = list(map(int, input().split()))
A = [input() for i in range(N)]
B = [input() for i in range(M)]
ans = 'No'
for i in range(N - M + 1):
	for j in range(N - M + 1):
		t = [k[j:j + M] for k in A[i:i + M]]
		if t == B:
			ans = 'Yes'
print(ans)


(n, m) = map(int, input().split())
A = [list(input()) for _ in range(n)]
B = [list(input()) for _ in range(m)]
BB = sum(B, [])
for i in range(n - m + 1):
	for k in range(n - m + 1):
		AA = []
		for v in range(m):
			AA += A[i + v][k:k + m]
		if BB == AA:
			print('Yes')
			quit()
print('No')


(N, M) = map(int, input().split())
A = [str(input()) for _ in range(N)]
B = [str(input()) for _ in range(M)]
res = 'No'
for i in range(N - M + 1):
	for j in range(N - M + 1):
		for k in range(M):
			if A[i + k][j:j + M] != B[k]:
				break
			if k == M - 1:
				res = 'Yes'
print(res)


(N, M) = map(int, input().split())
A = [0] * N
B = [0] * M
for _ in range(N):
	A[_] = input()
for _ in range(M):
	B[_] = input()
res = 'No'
for r in range(N - M + 1):
	for c in range(N - M + 1):
		if B == [e[r:r + M:1] for e in A[c:c + M:1]]:
			res = 'Yes'
			break
print(res)


(n, m) = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
for i in range(n - m + 1):
	for p in range(n - m + 1):
		for c in range(m):
			if B[c] != A[p + c][i:i + m]:
				break
		else:
			print('Yes')
			exit()
print('No')


(N, M) = map(int, input().split())
A = []
B = []
ans = 'Yes'
for _ in range(N):
	A.append(input().split())
for __ in range(M):
	B.append(input().split())
for i in range(N):
	for k in range(M):
		if B[k][0] not in A[i][0]:
			ans = 'No'
print(ans)


(n, m) = map(int, input().split())
A = [input() for _ in range(n)]
B = ''.join([input() for _ in range(m)])
na = n - (m - 1)
ans = 'No'
for i in range(na):
	A1 = ''.join([a[i:i + m] for a in A])
	if B in A1:
		ans = 'Yes'
		break
print(ans)


(n, m) = map(int, input().split())
A = []
B = []
for i in range(n):
	A.append(input())
for i in range(m):
	B.append(input())
cnt = 0
flag = False
for i in range(n - m + 1):
	for j in range(n - m + 1):
		ans = 'Yes'
		for k in range(m):
			for l in range(m):
				if A[i + k][j + l] != B[k][l]:
					ans = 'No'
		else:
			if ans == 'Yes':
				print(ans)
				return
print(ans)


(n, m) = map(int, input().split())
a = ''
b = ''
for i in range(n):
	a += input()
for i in range(m):
	if not i % 2 == 0:
		b += input()[::-1]
	else:
		b += input()
if b in a:
	print('Yes')
else:
	print('No')


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n - m + 1):
	for j in range(n - m + 1):
		if b == [w[j:j + m] for w in a[i:i + m]]:
			print('Yes')
			break
	else:
		continue
	break
else:
	print('No')


import re
(n, m) = [int(x) for x in input().split()]
nm = ''
ss = ''
for _ in range(n):
	nm += input()
for i in range(m):
	ss += '.{{{}}}'.format(n - m) if i > 0 else ''
	ss += input().replace('.', '\\.')
print('Yes') if re.search(ss, nm) else print('No')


(n, m) = map(int, input().split(' '))
a = [input() for i in range(n)]
b = [input() for i in range(m)]
for y in range(n - m + 1):
	for x in range(n - m + 1):
		if [line[x:x + m] for line in a[y:y + m]] == b:
			print('Yes')
			exit()
print('No')


(N, M) = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
arr = []
for i in range(N - M + 1):
	for j in range(N - M + 1):
		l = list(map(lambda x: x[j:j + M], A[i:i + M]))
		arr.append(all([l[j] == B[j] for j in range(M)]))
print('Yes' if any(arr) else 'No')


(N, M) = map(int, input().split())
Als = []
Bls = []
ans = 'No'
if Bls == Als:
	ans = 'Yes'
for i in range(N):
	Als.append(input())
for i in range(M):
	Bls.append(input())
for i in range(N - M):
	for j in range(0, N - M):
		for k in range(M):
			if Bls[k] == Als[i + k][j:M + j]:
				ans = 'Yes'
			else:
				ans = 'No'
				break
		if ans == 'Yes':
			break
	if ans == 'Yes':
		break
print(ans)


(n, m) = map(int, input().split())
nn = ''
mm = []
for i in range(n):
	nn += input() + '\n'
for i in range(m):
	mm.append(input() + '\n')
count = 0
for i in range(m):
	if mm[i] in nn:
		count += 1
if count == m:
	print('Yes')
else:
	print('No')


(n, m) = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
ans = False
for i in range(n - m + 1):
	for j in range(n - m + 1):
		part_a = [a[y][j:j + m] for y in range(i, i + m)]
		cnt = 0
		for k in range(m):
			for l in range(n - m + 1):
				if part_a[k][l:m + l] == b[k]:
					cnt += 1
		if cnt == m:
			ans = True
if ans:
	print('Yes')
else:
	print('No')


import sys
(N, M) = map(int, input().split())
A = []
for i in range(N):
	a = input()
	A.append(a)
B = []
for j in range(M):
	b = input()
	B.append(b)
for k in range(N - M + 1):
	for l in range(N - M + 1):
		z = 0
		for m in range(M):
			try:
				if B[m] == A[k + m][l:l + M]:
					z += 1
			except:
				sys.stderr.write(f'{(k, l, m)}')
				pass
		if z == M:
			print('Yes')
			return
print('No')