# -*- coding: utf-8 -*-

n, m = map(int, raw_input().split())

d = set()

import string
import hashlib

for i in xrange(n):
  s = raw_input()
  for i in xrange(len(s)):
    d.add( hashlib.md5( ''.join([s[:i], s[i+1:], str(i)]) ).hexdigest() )

for i in xrange(m):
  s = raw_input()
  flag = 0
  for i in xrange(len(s)):
    if hashlib.md5( ''.join([s[:i], s[i+1:], str(i)]) ).hexdigest() in d:
      flag = 1
      print 'YES'
      break
  if not flag:
    print 'NO'


# -*- coding: utf-8 -*-

d = set()
ss = []

MOD = 11**29

def calc(s):
  c = 0
  for i, w in enumerate(s):
    c += (11**i)*ord(w)
    c %= MOD
  return c

n, m = map(int, raw_input().split())
for _ in xrange(n):
  s = raw_input()
  ss.append(s)
  c = calc(s)
  for i, w in enumerate(s):
    it = ['a', 'b', 'c']
    it.remove(w)
    for r in it:
      k = c + MOD - ord(w)*(11**i) + ord(r)*(11**i)
      k %= MOD
      d.add(k)

for _ in xrange(m):
  s = raw_input()
  c = calc(s)
  if c in d:
    print 'YES'
  else:
    print 'NO'


# -*- coding: utf-8 -*-

n, m = map(int, raw_input().split())

d = set()

import string
import hashlib

for i in xrange(n):
  s = raw_input()
  for i in xrange(len(s)):
    for w in string.lowercase:
      if w != s[i]:
        d.add( hashlib.md5( ''.join([s[:i], w, s[i+1:]]) ).hexdigest() )

for i in xrange(m):
  s = hashlib.md5( raw_input() ).hexdigest()
  if s in d:
    print 'YES'
  else:
    print 'NO'


# -*- coding: utf-8 -*-

n, m = map(int, raw_input().split())

d = set()

for i in xrange(n):
  s = raw_input()
  d.add(s)

for _ in xrange(m):
  s = raw_input()

  flag = 0
  for i in xrange(len(s)):
    if flag: break
    for w in ['a', 'b', 'c']:
      if w == s[i]: continue
      ts = ''.join([ s[:i], w, s[i+1:] ])
      if ts in d:
        print 'YES'
        flag = 1
        break

  if not flag:
    print 'NO'


# -*- coding: utf-8 -*-

class mydict(dict):

  def __missing__(self, key):
    self[key] = []
    return self[key]

d = mydict()
ss = []

MOD = 1000000007

def calc(s):
  c = 0
  for i, w in enumerate(s):
    c += (1<<i)*ord(w)
    c %= MOD
  return c

n, m = map(int, raw_input().split())
for _ in xrange(n):
  s = raw_input()
  ss.append(s)
  c = calc(s)
  for i, w in enumerate(s):
    it = ['a', 'b', 'c']
    it.remove(w)
    for r in it:
      k = c + MOD - ord(w)*(1<<i) + ord(r)*(1<<i)
      k %= MOD
      d[k].append(_)

for _ in xrange(m):
  s = raw_input()
  c = calc(s)
  if c in d:
    print 'YES'
  else:
    print 'NO'


# -*- coding: utf-8 -*-

d = set()
ss = []

MOD = (2**64)-1

p = [0] * 200
for i in xrange(200):
  p[i] = 11**i

prime = 113

def calc(s):
  c = 0
  for i, w in enumerate(s):
    c += p[i%prime]*ord(w)
    c %= MOD
  return c

n, m = map(int, raw_input().split())
for _ in xrange(n):
  s = raw_input()
  ss.append(s)
  c = calc(s)
  for i, w in enumerate(s):
    it = ['a', 'b', 'c']
    it.remove(w)
    for r in it:
      k = c + MOD - ord(w)*p[i%prime] + ord(r)*p[i%prime]
      k %= MOD
      d.add(k)

for _ in xrange(m):
  s = raw_input()
  c = calc(s)
  if c in d:
    print 'YES'
  else:
    print 'NO'


# -*- coding: utf-8 -*-

n, m = map(int, raw_input().split())

d = set()

import string

for i in xrange(n):
  s = raw_input()
  for i in xrange(len(s)):
    for w in string.lowercase:
      if w != s[i]:
        d.add( ''.join([s[:i], w, s[i+1:]]) )

for i in xrange(m):
  s = raw_input()
  if s in d:
    print 'YES'
  else:
    print 'NO'


# -*- coding: utf-8 -*-

d = set()
ss = []

MOD = (1<<31)-1

def calc(s):
  c = 0
  for i, w in enumerate(s):
    c += (11**i)*ord(w)
    c %= MOD
  return c

n, m = map(int, raw_input().split())
for _ in xrange(n):
  s = raw_input()
  ss.append(s)
  c = calc(s)
  for i, w in enumerate(s):
    it = ['a', 'b', 'c']
    it.remove(w)
    for r in it:
      k = c + MOD - ord(w)*(11**i) + ord(r)*(11**i)
      k %= MOD
      d.add(k)

for _ in xrange(m):
  s = raw_input()
  c = calc(s)
  if c in d:
    print 'YES'
  else:
    print 'NO'


# -*- coding: utf-8 -*-

class mydict(dict):

  def __missing__(self, key):
    self[key] = []
    return self[key]

d = mydict()
ss = []

MOD = 1000000007

def calc(s):
  c = 0
  for i, w in enumerate(s):
    c += (i+1)*ord(w)
    c %= MOD
  return c

n, m = map(int, raw_input().split())
for _ in xrange(n):
  s = raw_input()
  ss.append(s)
  c = calc(s)
  for i, w in enumerate(s):
    it = ['a', 'b', 'c']
    it.remove(w)
    for r in it:
      k = c + MOD - ord(w)*(i+1) + ord(r)*(i+1)
      k %= MOD
      d[k].append(_)

for _ in xrange(m):
  s = raw_input()
  c = calc(s)
  isin = 0
  if c in d:
    for ind in d[c]:
      if len(s) == len( ss[ind] ):
        cnt = 0
        for i in xrange(len(s)):
          if s[i] != ss[ind][i]:
            cnt += 1
            if cnt > 1:
              break

        if cnt==1:
          isin = 1
          break

  if isin:
    print 'YES'
  else:
    print 'NO'


# -*- coding: utf-8 -*-

n, m = map(int, raw_input().split())

d = set()

import string

for i in xrange(n):
  s = raw_input()
  d.add(s)

for _ in xrange(m):
  s = raw_input()

  if len(s) > 1000:
    flag = 0
    for t in d:
      if flag: break
      if len(t) == len(s):
        for i in xrange(len(s)):
          if s[i] != t[i] and s[:i]+s[i+1:] == t[:i]+t[i+1:]:
            print 'YES'
            flag = 1
            break

    print 'NO'
    continue

  flag = 0
  for i in xrange(len(s)):
    if flag: break
    for w in string.lowercase:
      if w == s[i]: continue
      ts = ''.join([ s[:i], w, s[i+1:] ])
      if ts in d:
        print 'YES'
        flag = 1
        break

  if not flag:
    print 'NO'


# -*- coding: utf-8 -*-

d = set()
ss = []

MOD = (2**64)-1

def calc(s):
  c = 0
  for i, w in enumerate(s):
    c += (11**(i%63))*ord(w)
    c %= MOD
  return c

n, m = map(int, raw_input().split())
for _ in xrange(n):
  s = raw_input()
  ss.append(s)
  c = calc(s)
  for i, w in enumerate(s):
    it = ['a', 'b', 'c']
    it.remove(w)
    for r in it:
      k = c + MOD - ord(w)*(11**(i%63)) + ord(r)*(11**(i%63))
      k %= MOD
      d.add(k)

for _ in xrange(m):
  s = raw_input()
  c = calc(s)
  if c in d:
    print 'YES'
  else:
    print 'NO'


# -*- coding: utf-8 -*-

n, m = map(int, raw_input().split())

d = set()

import string

for i in xrange(n):
  s = raw_input()
  d.add(s)

for _ in xrange(m):
  s = raw_input()
  flag = 0
  for i in xrange(len(s)):
    if flag: break
    for w in string.lowercase:
      ts = ''.join([ s[:i], w, s[i+1:] ])
      if ts in d:
        print 'YES'
        flag = 1
        break

  if not flag:
    print 'NO'


# -*- coding: utf-8 -*-

d = set()
ss = []

MOD = (2**64)-1

p = [0] * 200
for i in xrange(200):
  p[i] = 11**i

prime = 193

def calc(s):
  c = 0
  for i, w in enumerate(s):
    c += p[i%prime]*ord(w)
    c %= MOD
  return c

n, m = map(int, raw_input().split())
for _ in xrange(n):
  s = raw_input()
  ss.append(s)
  c = calc(s)
  for i, w in enumerate(s):
    it = ['a', 'b', 'c']
    it.remove(w)
    for r in it:
      k = c + MOD - ord(w)*p[i%prime] + ord(r)*p[i%prime]
      k %= MOD
      d.add(k)

for _ in xrange(m):
  s = raw_input()
  c = calc(s)
  if c in d:
    print 'YES'
  else:
    print 'NO'


# -*- coding: utf-8 -*-

"""
  Also can use trie, but we can use polynomial hash
"""

d = set()
ss = set()

MOD = (2**64)-1

p = [0] * 200
for i in xrange(200):
  p[i] = 11**i

prime = 63

def calc(s):
  c = 0
  for i, w in enumerate(s):
    c += p[i%prime]*ord(w)
    c %= MOD
  return c

n, m = map(int, raw_input().split())
for _ in xrange(n):
  s = raw_input()
  ss.add(s)
  c = calc(s)
  d.add(c)

for _ in xrange(m):
  s = raw_input()
  c = calc(s)
  flag = 0
  for i, w in enumerate(s):
    it = ['a', 'b', 'c']
    it.remove(w)
    for r in it:
      k = c + MOD - ord(w)*p[i%prime] + ord(r)*p[i%prime]
      k %= MOD
      if k in d and (s[:i]+r+s[i+1:]) in ss:
        flag = 1
        break
    if flag:break

  if flag:
    print 'YES'
  else:
    print 'NO'


# -*- coding: utf-8 -*-

d = set()
ss = []

MOD = (2**64)-1

p = [0] * 100
for i in xrange(100):
  p[i] = 11**i

def calc(s):
  c = 0
  for i, w in enumerate(s):
    c += p[i%97]*ord(w)
    c %= MOD
  return c

n, m = map(int, raw_input().split())
for _ in xrange(n):
  s = raw_input()
  ss.append(s)
  c = calc(s)
  for i, w in enumerate(s):
    it = ['a', 'b', 'c']
    it.remove(w)
    for r in it:
      k = c + MOD - ord(w)*p[i%97] + ord(r)*p[i%97]
      k %= MOD
      d.add(k)

for _ in xrange(m):
  s = raw_input()
  c = calc(s)
  if c in d:
    print 'YES'
  else:
    print 'NO'


# -*- coding: utf-8 -*-

n, m = map(int, raw_input().split())

d = set()

for i in xrange(n):
  s = raw_input()
  d.add(s)

for _ in xrange(m):
  s = raw_input()

  if len(s) > 1000:
    flag = 0
    for t in d:
      if flag: break
      if len(t) == len(s):
        for i in xrange(len(s)):
          if s[i] != t[i] and s[:i]+s[i+1:] == t[:i]+t[i+1:]:
            print 'YES'
            flag = 1
            break

    print 'NO'
    continue

  flag = 0
  for i in xrange(len(s)):
    if flag: break
    for w in ['a', 'b', 'c']:
      if w == s[i]: continue
      ts = ''.join([ s[:i], w, s[i+1:] ])
      if ts in d:
        print 'YES'
        flag = 1
        break

  if not flag:
    print 'NO'


# -*- coding: utf-8 -*-

d = set()
ss = []

MOD = (2**64)-1

def calc(s):
  c = 0
  for i, w in enumerate(s):
    c += (11**(i%97))*ord(w)
    c %= MOD
  return c

n, m = map(int, raw_input().split())
for _ in xrange(n):
  s = raw_input()
  ss.append(s)
  c = calc(s)
  for i, w in enumerate(s):
    it = ['a', 'b', 'c']
    it.remove(w)
    for r in it:
      k = c + MOD - ord(w)*(11**(i%97)) + ord(r)*(11**(i%97))
      k %= MOD
      d.add(k)

for _ in xrange(m):
  s = raw_input()
  c = calc(s)
  if c in d:
    print 'YES'
  else:
    print 'NO'


from sys import stdin, stdout
from collections import defaultdict
def main():
    n, m = map(int, stdin.readline().split())
    ss = stdin.read().split()
    mod0 = 1000000007
    mod1 = 1000000009
    toi = {'a': 0, 'b': 1, 'c': 2}
    d = defaultdict(set)
    for s in ss[:n]:
        k0 = k1 = 0
        for c in s:
            k0 = (k0 + k0 + k0 + toi[c]) % mod0
            k1 = (k1 + k1 + k1 + toi[c]) % mod1
        d[len(s)].add((k0, k1))
    al = [(1, 2), (-1, 1), (-2, -1)]
    def f(s):
        k0 = k1 = 0
        for c in s:
            k0 = (k0 + k0 + k0 + toi[c]) % mod0
            k1 = (k1 + k1 + k1 + toi[c]) % mod1
        S = d[len(s)]
        f = 0
        x0 = x1 = 1
        for c in reversed(s):
            c = toi[c]
            for a in al[c]:
                nk = ((k0 + a * x0) % mod0, (k1 + a * x1) % mod1)
                if nk in S:
                    return "YES"
            x0 = x0 * 3 % mod0
            x1 = x1 * 3 % mod1
        return "NO"
    stdout.write("\n".join(map(f, ss[n:])))
main()


from collections import defaultdict

#
#
# def hashRS(oldVal, a, char):
#     return oldVal * a + ord(char), a * 378551
#
#
# def solve(s):
#     preHash = 0
#     sufHash = 0
#     a = 63689
#     count = 0
#     for i in xrange(len(s) - 1):
#         preHash, _ = hashRS(preHash, a, s[i])
#         sufHash, a = sufHash + hashRS(sufHash, a, s[len(s) - i - 1])
#         if preHash == sufHash:
#             if s[:i + 1] == s[len(s) - i - 1:]:
#                 count += 1
#     return count
#
MOD = 10000000007

def hashPR(s):
    h = 0
    a = 1
    for i in xrange(len(s)):
        h = (h + ord(s[i]) * a) % MOD
        a *= 33
        a %= MOD
    return h

ssss = {"a", "b", "c"}

def nono(c):
    for cc in ssss:
        if cc != c:
            yield cc

def generateStrings(s):
    h = hashPR(s)
    a = 1
    for i in xrange(len(s)):
        for cc in nono(s[i]):
            hh = h + (ord(cc) - ord(s[i])) * a
            hh %= MOD
            yield hh
        a *= 33
        a %= MOD

def good(q, H):
    for ss in generateStrings(q):
        if ss in H:
            return True
    return False

def solve(strs, qs):
    H = set()
    for s in strs:
        H.add(hashPR(s))

    for q in qs:
        if good(q, H):
            print "YES"
        else:
            print "NO"

N, M = map(int, raw_input().split(" "))
strs = []
for _ in xrange(N):
    strs.append(raw_input())
Qs = []
for _ in xrange(M):
    Qs.append(raw_input())
solve(strs, Qs)


from collections import defaultdict

#
#
# def hashRS(oldVal, a, char):
#     return oldVal * a + ord(char), a * 378551
#
#
# def solve(s):
#     preHash = 0
#     sufHash = 0
#     a = 63689
#     count = 0
#     for i in xrange(len(s) - 1):
#         preHash, _ = hashRS(preHash, a, s[i])
#         sufHash, a = sufHash + hashRS(sufHash, a, s[len(s) - i - 1])
#         if preHash == sufHash:
#             if s[:i + 1] == s[len(s) - i - 1:]:
#                 count += 1
#     return count
#
MOD = 100000009007

def hashPR(s):
    h = 0
    a = 1
    for i in xrange(len(s)):
        h = (h + ord(s[i]) * a) % MOD
        a *= 33
        a %= MOD
    return h

ssss = {"a", "b", "c"}

def nono(c):
    for cc in ssss:
        if cc != c:
            yield cc

def generateStrings(s):
    h = hashPR(s)
    a = 1
    for i in xrange(len(s)):
        for cc in nono(s[i]):
            hh = h + (ord(cc) - ord(s[i])) * a
            hh %= MOD
            yield hh
        a *= 33
        a %= MOD

def good(q, H):
    for ss in generateStrings(q):
        if ss in H:
            return True
    return False

def solve(strs, qs):
    H = set()
    for s in strs:
        H.add(hashPR(s))

    for q in qs:
        if good(q, H):
            print "YES"
        else:
            print "NO"

N, M = map(int, raw_input().split(" "))
strs = []
for _ in xrange(N):
    strs.append(raw_input())
Qs = []
for _ in xrange(M):
    Qs.append(raw_input())
solve(strs, Qs)


import sys
n,m = map(int,sys.stdin.readline().split())
L = {}
ans = ""
for i in range(n):
    s = sys.stdin.readline()
    l = len(s)-1
    x = 0
    u = 1
    for j in range(l-1,-1,-1):
        if(s[j]=='b'):
            x+=u
        elif(s[j]=='c'):
            x+=2*u
        u*=3
    L[(x,l)] = 1

for i in range(m):
    s = sys.stdin.readline()
    l = len(s)-1
    x = 0
    u = 1
    for j in range(l-1,-1,-1):
        if(s[j]=='b'):
            x+=u
        elif(s[j]=='c'):
            x+=2*u
        u*=3
    valid = False
    u = 1
    for j in range(l-1,-1,-1):
        if(s[j]=='a'):
            if((x+u,l) in L or (x+2*u,l) in L):
                valid = True
        elif(s[j]=='b'):
            if((x-u,l) in L or (x+u,l) in L):
                valid = True
        else:
            if((x-u,l) in L or (x-2*u,l) in L):
                valid = True
        u*=3
        if(valid):
            break
    if(valid):
        ans+="YES\n";
    else:
        ans+="NO\n";
sys.stdout.write(ans)


import sys
n,m = map(int,sys.stdin.readline().split())
L = {}
ans = ""
mod = 10**15+7
for i in range(n):
    s = sys.stdin.readline()
    l = len(s)-1
    x = 0
    u = 1
    for j in range(l-1,-1,-1):
        if(s[j]=='b'):
            x+=u
        elif(s[j]=='c'):
            x+=2*u
        u*=3
        u%=(10**15+7)
        x%=(10**15+7)
    L[(x,l)] = 1

for i in range(m):
    s = sys.stdin.readline()
    l = len(s)-1
    x = 0
    u = 1
    for j in range(l-1,-1,-1):
        if(s[j]=='b'):
            x+=u
        elif(s[j]=='c'):
            x+=2*u
        u*=3
        u%=(10**15+7)
        x%=(10**15+7)
    valid = False
    u = 1
    for j in range(l-1,-1,-1):
        if(s[j]=='a'):
            if(((x+u)%mod,l) in L or ((x+2*u)%mod,l) in L):
                valid = True
        elif(s[j]=='b'):
            if(((x-u+mod)%mod,l) in L or ((x+u)%mod,l) in L):
                valid = True
        else:
            if(((x-u+mod)%mod,l) in L or ((x-2*u+2*mod)%mod,l) in L):
                valid = True
        u*=3
        u%=(10**15+7)
        x%=(10**15+7)
        if(valid):
            break
    if(valid):
        ans+="YES\n";
    else:
        ans+="NO\n";
sys.stdout.write(ans)


import sys
n,m = map(int,sys.stdin.readline().split())
L = {}
ans = ""
mod = 10**9+7
for i in range(n):
    s = sys.stdin.readline()
    l = len(s)-1
    x = 0
    u = 1
    for j in range(l-1,-1,-1):
        if(s[j]=='b'):
            x+=u
        elif(s[j]=='c'):
            x+=2*u
        u*=3
        u%=(10**9+7)
        x%=(10**9+7)
    L[(x,l)] = 1

for i in range(m):
    s = sys.stdin.readline()
    l = len(s)-1
    x = 0
    u = 1
    for j in range(l-1,-1,-1):
        if(s[j]=='b'):
            x+=u
        elif(s[j]=='c'):
            x+=2*u
        u*=3
        u%=(10**9+7)
        x%=(10**9+7)
    valid = False
    u = 1
    for j in range(l-1,-1,-1):
        if(s[j]=='a'):
            if(((x+u)%mod,l) in L or ((x+2*u)%mod,l) in L):
                valid = True
        elif(s[j]=='b'):
            if(((x-u+mod)%mod,l) in L or ((x+u)%mod,l) in L):
                valid = True
        else:
            if(((x-u+mod)%mod,l) in L or ((x-2*u+2*mod)%mod,l) in L):
                valid = True
        u*=3
        u%=(10**9+7)
        x%=(10**9+7)
        if(valid):
            break
    if(valid):
        ans+="YES\n";
    else:
        ans+="NO\n";
sys.stdout.write(ans)


mod = 1000000000000000003

def hsh(s):
	h = 0
	for c in s:
		h = (ord(c) - ord('a') + 3*h)%mod
	return h

known = {}  # hsh -> [matches]

n, m = map(int, raw_input().split())

for _ in xrange(n):
	s = raw_input().strip()
	known.setdefault(hsh(s), []).append(s)

for _ in xrange(m):
	s = raw_input().strip()
	h = hsh(s)
	found = False
	b = 1
	for i in xrange(len(s)-1, -1, -1):
		for c in ['a', 'b', 'c']:
			if s[i] != c:
				h2 = (h + b*(ord(c) - ord(s[i])))%mod
				if h2 in known:
					s2 = s[:i] + c + s[i+1:]
					for ks in known[h2]:
						if ks == s2:
							found = True
							break
			if found:
				break
		if found:
			break
		b = 3*b%mod
	if found:
		print 'YES'
	else:
		print 'NO'


def hsh(s):
	h = 0
	for c in s:
		h = 3*(ord(c) - ord('a')) + 3*h
	return h

known = {}  # hsh -> [matches]

n, m = map(int, raw_input().split())

for _ in xrange(n):
	s = raw_input().strip()
	known.setdefault(hsh(s), []).append(s)

for _ in xrange(m):
	s = raw_input().strip()
	found = False
	for i in xrange(len(s)):
		for c in ['a', 'b', 'c']:
			if s[i] != c:
				t = s[:i] + c + s[i+1:]
				h = hsh(t)
				for s in known.get(h, []):
					if s == t:
						found = True
						break
			if found:
				break
		if found:
			break
	if found:
		print 'YES'
	else:
		print 'NO'


# C. Watto and Mechanism

modprime = 1e9 + 7
mulprime = 5
strs = {}

def powermod(base, exponent, mod):
	base %= mod
	result = 1
	while(exponent > 0):
		if (exponent & 1): # odd; This is 0 when exponent is even
			result = (result * base) % mod
		base = (base * base) % mod
		exponent >>= 1
	return result

def strhash(s):
	ans = 0
	for ch in s:
		ans = (ans * mulprime + (ord(ch) - 96)) % modprime # only x in 'abc' allowed ie small letters
	return ans

def querycheck(query):
	queryhash = strhash(query)
	powerup = 1;
	for i in xrange(len(query) - 1, -1, -1):
		if query[i] == 'a':
			hashed = (queryhash - powerup) % modprime

			modstr = query[:i] + 'b' + query[i+1:]
			temphash = (hashed + powerup * 2) % modprime
			if (temphash in strs and modstr in strs[temphash]):
				print 'YES'
				return 1

			modstr = query[:i] + 'c' + query[i+1:]
			temphash = (hashed + powerup * 3) % modprime
			if (temphash in strs and modstr in strs[temphash]):
				print 'YES'
				return 1

		elif query[i] == 'b':
			hashed = (queryhash - 2 * powerup) % modprime

			modstr = query[:i] + 'a' + query[i+1:]
			temphash = (hashed + powerup) % modprime
			if (temphash in strs and modstr in strs[temphash]):
				print 'YES'
				return 1

			modstr = query[:i] + 'c' + query[i+1:]
			temphash = (hashed + powerup * 3) % modprime
			if (temphash in strs and modstr in strs[temphash]):
				print 'YES'
				return 1

		else: # query[i] == 'c'
			hashed = (queryhash - 3 * powerup) % modprime

			modstr = query[:i] + 'a' + query[i+1:]
			temphash = (hashed + powerup) % modprime
			if (temphash in strs and modstr in strs[temphash]):
				print 'YES'
				return 1

			modstr = query[:i] + 'b' + query[i+1:]
			temphash = (hashed + powerup * 2) % modprime
			if (temphash in strs and modstr in strs[temphash]):
				print 'YES'
				return 1

		powerup = (powerup * mulprime) % modprime
	print 'NO'
	return 0

def inputs():
	global strs, strhashes
	N, M = map(int, raw_input().split())
	for _ in xrange(N):
		inpstr = raw_input()
		hashed = strhash(inpstr)
		if hashed in strs:
			strs[hashed].append(inpstr)
		else:
			strs[hashed] = [inpstr]

	for _ in xrange(M):
		querycheck(raw_input())

inputs()


# C. Watto and Mechanism

modprime = 1e9 + 7
mulprime = 5
strs = {}

def binary_search(A, key, imin, imax):
	if(imin > imax):
		return -1
	imid = imin + (imax - imin) / 2
	if(A[imid] > key):
		return binary_search(A, key, imin, imid - 1)
	elif(A[imid] < key):
		return binary_search(A, key, imid + 1, imax)
	else:
		return imid

def bs(A, key):
	return binary_search(A, key, 0, len(A) - 1)

def powermod(base, exponent, mod):
	base %= mod
	result = 1
	while(exponent > 0):
		if (exponent & 1): # odd; This is 0 when exponent is even
			result = (result * base) % mod
		base = (base * base) % mod
		exponent >>= 1
	return result

def strhash(s):
	ans = 0
	for ch in s:
		ans = (ans * mulprime + (ord(ch) - 96)) % modprime # only x in 'abc' allowed ie small letters
	return ans

def inputs():
	global strs, strhashes
	N, M = map(int, raw_input().split())
	for _ in xrange(N):
		inpstr = raw_input()
		hashed = strhash(inpstr)
		if hashed in strs:
			strs[hashed].append(inpstr)
		else:
			strs[hashed] = [inpstr]

	# zipper = sorted(zip(strhashes, strs))
	# strhashes = [x[0] for x in zipper]
	# strs = [x[1] for x in zipper]

	for _ in xrange(M):
		query = raw_input()
		isMatch = False
		for i in xrange(len(query)):
			for x in 'abc':
				modstr = query[:i] + x + query[i+1:]
				hashed = strhash(modstr)
				# searchresult = bs(strhashes, strhash(modstr))
				if (hashed in strs and modstr in strs[hashed]):
					isMatch = True
					break
			if isMatch:
				break

		if isMatch:
			print 'YES'
		else:
			print 'NO'

inputs()


# C. Watto and Mechanism
import hashlib

hasher = hashlib.sha1()

modprime = 1e9 + 7
mulprime = 7
strs = []
strhashes = []

def binary_search(A, key, imin, imax):
	if(imin > imax):
		return -1
	imid = imin + (imax - imin) / 2
	if(A[imid] > key):
		return binary_search(A, key, imin, imid - 1)
	elif(A[imid] < key):
		return binary_search(A, key, imid + 1, imax)
	else:
		return imid

def bs(A, key):
	return binary_search(A, key, 0, len(A) - 1)

def powermod(base, exponent, mod):
	base %= mod
	result = 1
	while(exponent > 0):
		if (exponent & 1): # odd; This is 0 when exponent is even
			result = (result * base) % mod
		base = (base * base) % mod
		exponent >>= 1
	return result

def strhash(s):
	A = [ord(s[0])]
	for i in xrange(1, len(s)):
		A.append(int((A[-1] + ord(s[i]) * powermod(mulprime, i, modprime)) % modprime))
	return A

def inputs():
	global strs, strhashes
	N, M = map(int, raw_input().split())
	for _ in xrange(N):
		inpstr = raw_input()
		strs.append(inpstr)
		strhashes.append(hash(inpstr))

	zipper = sorted(zip(strhashes, strs))
	strhashes = [x[0] for x in zipper]
	strs = [x[1] for x in zipper]

	for _ in xrange(M):
		query = raw_input()
		isMatch = False
		# queries.append(raw_input())
		for i in xrange(len(query)):
			# if any(bs(strs, hash(query[0:i] + x + query[i+1:])) for x in 'abc'):
			# 	isMatch = True
			# 	break
			for x in 'abc':
				modstr = query[0:i] + x + query[i+1:]
				searchresult = bs(strhashes, hash(modstr))
				if (searchresult != -1 and strs[searchresult] == modstr):
					isMatch = True
					break
			if isMatch:
				break

		if isMatch:
			print 'YES'
		else:
			print 'NO'

inputs()


# C. Watto and Mechanism

modprime = 1e9 + 7
mulprime = 4
strs = {}

def strhash(s):
	ans = 0
	for ch in s:
		ans = (ans * mulprime + (ord(ch) - 96)) % modprime # only x in 'abc' allowed ie small letters
	return ans

def querycheck(query):
	queryhash = strhash(query)
	powerup = 1;
	for i in xrange(len(query) - 1, -1, -1):
		if query[i] == 'a':
			hashed = (queryhash + powerup) % modprime
			if hashed in strs:
				if query[:i] + 'b' + query[i+1:] in strs[hashed]:
					return 1

			hashed = (queryhash + 2 * powerup) % modprime
			if hashed in strs:
				if query[:i] + 'c' + query[i+1:] in strs[hashed]:
					return 1

		elif query[i] == 'b':
			hashed = (queryhash - powerup) % modprime
			if hashed in strs:
				if query[:i] + 'a' + query[i+1:] in strs[hashed]:
					return 1

			hashed = (queryhash + powerup) % modprime
			if hashed in strs:
				if query[:i] + 'c' + query[i+1:] in strs[hashed]:
					return 1

		else: # query[i] == 'c'
			hashed = (queryhash - 2 * powerup) % modprime
			if hashed in strs:
				if query[:i] + 'a' + query[i+1:] in strs[hashed]:
					return 1

			hashed = (queryhash - powerup) % modprime
			if hashed in strs:
				if query[:i] + 'b' + query[i+1:] in strs[hashed]:
					return 1

		powerup = (powerup * mulprime) % modprime
	return 0

def inputs():
	global strs, strhashes
	N, M = map(int, raw_input().split())
	for _ in xrange(N):
		inpstr = raw_input()
		hashed = strhash(inpstr)
		if hashed in strs:
			strs[hashed].append(inpstr)
		else:
			strs[hashed] = [inpstr]

	for _ in xrange(M):
		if querycheck(raw_input()):
			print 'YES'
		else:
			print 'NO'

inputs()


# C. Watto and Mechanism

modprime = 1e9 + 7
mulprime = 5
strs = {}

def powermod(base, exponent, mod):
	base %= mod
	result = 1
	while(exponent > 0):
		if (exponent & 1): # odd; This is 0 when exponent is even
			result = (result * base) % mod
		base = (base * base) % mod
		exponent >>= 1
	return result

def strhash(s):
	ans = 0
	for ch in s:
		ans = (ans * mulprime + (ord(ch) - 96)) % modprime # only x in 'abc' allowed ie small letters
	return ans

def inputs():
	global strs, strhashes
	N, M = map(int, raw_input().split())
	for _ in xrange(N):
		inpstr = raw_input()
		hashed = strhash(inpstr)
		if hashed in strs:
			strs[hashed].append(inpstr)
		else:
			strs[hashed] = [inpstr]

	# zipper = sorted(zip(strhashes, strs))
	# strhashes = [x[0] for x in zipper]
	# strs = [x[1] for x in zipper]

	for _ in xrange(M):
		query = raw_input()
		isMatch = False
		for i in xrange(len(query)):
			tocheck = 'ab'
			if query[i] == 'a':
				tocheck = 'bc'
			elif query[i] == 'b':
				tocheck = 'ac'
			for x in tocheck:
				modstr = query[:i] + x + query[i+1:]
				hashed = strhash(modstr)
				# searchresult = bs(strhashes, strhash(modstr))
				if (hashed in strs and modstr in strs[hashed]):
					isMatch = True
					break
			if isMatch:
				break

		if isMatch:
			print 'YES'
		else:
			print 'NO'

inputs()


# C. Watto and Mechanism

modprime = 1e9 + 7
mulprime = 7
strs = []

def binary_search(A, key, imin, imax):
	if(imin > imax):
		return False
	imid = imin + (imax - imin) / 2
	if(A[imid] > key):
		return binary_search(A, key, imin, imid - 1)
	elif(A[imid] < key):
		return binary_search(A, key, imid + 1, imax)
	else:
		return True

def bs(A, key):
	return binary_search(A, key, 0, len(A) - 1)

def powermod(base, exponent, mod):
	base %= mod
	result = 1
	while(exponent > 0):
		if (exponent & 1): # odd; This is 0 when exponent is even
			result = (result * base) % mod
		base = (base * base) % mod
		exponent >>= 1
	return result

def strhash(s):
	A = [ord(s[0])]
	for i in xrange(1, len(s)):
		A.append(int((A[-1] + ord(s[i]) * powermod(mulprime, i, modprime)) % modprime))
	return A

def inputs():
	global strs
	N, M = map(int, raw_input().split())
	for _ in xrange(N):
		strs.append(hash(raw_input()))
	strs.sort()
	for _ in xrange(M):
		query = raw_input()
		isMatch = False
		# queries.append(raw_input())
		for i in xrange(len(query)):
			if any(bs(strs, hash(query[0:i] + x + query[i+1:])) for x in 'abc'):
				isMatch = True
				break

		if isMatch:
			print 'YES'
		else:
			print 'NO'

inputs()


# C. Watto and Mechanism

modprime = 1e9 + 7
mulprime = 5
strs = []
strhashes = []

def binary_search(A, key, imin, imax):
	if(imin > imax):
		return -1
	imid = imin + (imax - imin) / 2
	if(A[imid] > key):
		return binary_search(A, key, imin, imid - 1)
	elif(A[imid] < key):
		return binary_search(A, key, imid + 1, imax)
	else:
		return imid

def bs(A, key):
	return binary_search(A, key, 0, len(A) - 1)

def powermod(base, exponent, mod):
	base %= mod
	result = 1
	while(exponent > 0):
		if (exponent & 1): # odd; This is 0 when exponent is even
			result = (result * base) % mod
		base = (base * base) % mod
		exponent >>= 1
	return result

def strhash(s):
	ans = 0
	for ch in s:
		ans = (ans * mulprime + (ord(ch) - 96)) % modprime # only x in 'abc' allowed ie small letters
	return ans

def inputs():
	global strs, strhashes
	N, M = map(int, raw_input().split())
	for _ in xrange(N):
		inpstr = raw_input()
		strs.append(inpstr)
		strhashes.append(strhash(inpstr))

	zipper = sorted(zip(strhashes, strs))
	strhashes = [x[0] for x in zipper]
	strs = [x[1] for x in zipper]

	for _ in xrange(M):
		query = raw_input()
		isMatch = False
		for i in xrange(len(query)):
			for x in 'abc':
				modstr = query[0:i] + x + query[i+1:]
				searchresult = bs(strhashes, strhash(modstr))
				if (searchresult != -1 and strs[searchresult] == modstr):
					isMatch = True
					break
			if isMatch:
				break

		if isMatch:
			print 'YES'
		else:
			print 'NO'

inputs()


# C. Watto and Mechanism

modprime = 1e9 + 7
mulprime = 5
strs = {}

def powermod(base, exponent, mod):
	base %= mod
	result = 1
	while(exponent > 0):
		if (exponent & 1): # odd; This is 0 when exponent is even
			result = (result * base) % mod
		base = (base * base) % mod
		exponent >>= 1
	return result

def strhash(s):
	ans = 0
	for ch in s:
		ans = (ans * mulprime + (ord(ch) - 96)) % modprime # only x in 'abc' allowed ie small letters
	return ans

def inputs():
	global strs, strhashes
	N, M = map(int, raw_input().split())
	for _ in xrange(N):
		inpstr = raw_input()
		hashed = hash(inpstr)
		if hashed in strs:
			strs[hashed].append(inpstr)
		else:
			strs[hashed] = [inpstr]

	for _ in xrange(M):
		query = raw_input()
		isMatch = False
		for i in xrange(len(query)):
			tocheck = 'ab'
			if query[i] == 'a':
				tocheck = 'bc'
			elif query[i] == 'b':
				tocheck = 'ac'
			for x in tocheck:
				modstr = query[:i] + x + query[i+1:]
				hashed = hash(modstr)
				if (hashed in strs and modstr in strs[hashed]):
					isMatch = True
					break
			if isMatch:
				break

		if isMatch:
			print 'YES'
		else:
			print 'NO'

inputs()


# C. Watto and Mechanism

modprime = 1e9 + 7
mulprime = 5
strs = {}

def powermod(base, exponent, mod):
	base %= mod
	result = 1
	while(exponent > 0):
		if (exponent & 1): # odd; This is 0 when exponent is even
			result = (result * base) % mod
		base = (base * base) % mod
		exponent >>= 1
	return result

def strhash(s):
	ans = 0
	for ch in s:
		ans = (ans * mulprime + (ord(ch) - 96)) % modprime # only x in 'abc' allowed ie small letters
	return ans

def inputs():
	global strs, strhashes
	N, M = map(int, raw_input().split())
	for _ in xrange(N):
		inpstr = raw_input()
		hashed = strhash(inpstr)
		if hashed in strs:
			strs[hashed].append(inpstr)
		else:
			strs[hashed] = [inpstr]

	# zipper = sorted(zip(strhashes, strs))
	# strhashes = [x[0] for x in zipper]
	# strs = [x[1] for x in zipper]

	for _ in xrange(M):
		query = raw_input()
		isMatch = False
		for i in xrange(len(query)):
			tocheck = 'ab'
			if i == 'a':
				tocheck = 'bc'
			elif i == 'b':
				tocheck = 'ac'
			for x in tocheck:
				modstr = query[:i] + x + query[i+1:]
				hashed = strhash(modstr)
				# searchresult = bs(strhashes, strhash(modstr))
				if (hashed in strs and modstr in strs[hashed]):
					isMatch = True
					break
			if isMatch:
				break

		if isMatch:
			print 'YES'
		else:
			print 'NO'

inputs()


# C. Watto and Mechanism

modprime = 1e9 + 7
mulprime = 5
strs = {}

def powermod(base, exponent, mod):
	base %= mod
	result = 1
	while(exponent > 0):
		if (exponent & 1): # odd; This is 0 when exponent is even
			result = (result * base) % mod
		base = (base * base) % mod
		exponent >>= 1
	return result

def strhash(s):
	ans = 0
	for ch in s:
		ans = (ans * mulprime + (ord(ch) - 96)) % modprime # only x in 'abc' allowed ie small letters
	return ans

def querycheck(query):
	queryhash = strhash(query)
	powerup = 1;
	isMatch = False
	for i in xrange(len(query) - 1, -1, -1):
		tocheck = 'ab'
		if query[i] == 'a':
			hashed = (queryhash - powerup) % modprime
			tocheck = 'bc'
		elif query[i] == 'b':
			hashed = (queryhash - 2 * powerup) % modprime
			tocheck = 'ac'
		else: # query[i] == 'c'
			hashed = (queryhash - 3 * powerup) % modprime
			tocheck = 'ab'

		for x in tocheck:
			modstr = query[:i] + x + query[i+1:]
			temphash = (hashed + powerup * (ord(x) - 96)) % modprime
			if (temphash in strs and modstr in strs[temphash]):
				isMatch = True
				break
		if isMatch:
			break
		powerup = (powerup * mulprime) % modprime

	if isMatch:
		print 'YES'
	else:
		print 'NO'

def inputs():
	global strs, strhashes
	N, M = map(int, raw_input().split())
	for _ in xrange(N):
		inpstr = raw_input()
		hashed = strhash(inpstr)
		if hashed in strs:
			strs[hashed].append(inpstr)
		else:
			strs[hashed] = [inpstr]

	for _ in xrange(M):
		querycheck(raw_input())

inputs()


MOD = 1000000000 + 7

def do_hash(s):
    h = 0

    for c in s[::-1]:
        h = h * 3 + ord(c) - ord('a')
        h %= MOD

    return h

if __name__ == '__main__':
    (n, m) = map(int, raw_input().split())
    d = {}
    for i in xrange(n):
        s = raw_input()
        h = do_hash(s)
        d[h] = d.get(h, [])
        d[h].append((len(s), s))

    for i in xrange(m):
        try:
            s = raw_input()
            lens = len(s)
            h = do_hash(s)

            u = 1
            for idx, c in enumerate(s):
                v = ord(c) - ord('a')
                hh = ((h - v * u) % MOD + MOD) % MOD
                for i in xrange(3):
                    if i == v:
                        continue
                    hhh = (hh + i * u) % MOD
                    if hhh in d:
                        sss = s[:idx] + chr(i + ord('a')) + s[idx + 1:]
                        for (l, ss) in d[hhh]:
                            if ss == sss:
                                raise 'done'
                u = (u * 3) % MOD
            print 'NO'
        except:
            print 'YES'


MOD = 1000000000 + 7

def do_hash(s):
    h = 0

    for c in s[::-1]:
        h = h * 3 + ord(c) - ord('a')
        h %= MOD

    return h

if __name__ == '__main__':
    (n, m) = map(int, raw_input().split())
    d = {}
    for i in xrange(n):
        s = raw_input()
        h = do_hash(s)
        d[h] = d.get(h, [])
        d[h].append((len(s), s))

    for i in xrange(m):
        try:
            s = raw_input()
            lens = len(s)
            h = do_hash(s)

            u = 1
            for idx, c in enumerate(s):
                v = ord(c) - ord('a')
                hh = ((h - v * u) % MOD + MOD) % MOD
                for i in xrange(3):
                    if i == v:
                        continue
                    hhh = (hh + i * u) % MOD
                    sss = s[:idx] + chr(i + ord('a')) + s[idx + 1:]
                    if hhh in d:
                        for (l, ss) in d[hhh]:
                            if ss == sss:
                                raise 'done'
                u = (u * 3) % MOD
            print 'NO'
        except:
            print 'YES'


import sys

MAXN = 10 ** 15 + 3

def calc(string):
    ans = 0
    for ch in string:
        ans = (ans * 3 + ord(ch) - 96) % MAXN
    return ans

def check(string):
    tmp = calc(string)
    for i in xrange(len(string)):
        if string[i] == 'a':
            temp = (tmp + 3 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'b' + string[i+1:] in H[temp]:
                    return 1
            temp = (tmp + 2 * 3 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'c' + string[i+1:] in H[temp]:
                    return 1
        if string[i] == 'b':
            temp = (tmp + 3 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'c' + string[i+1:] in H[temp]:
                    return 1
            temp = (tmp - 3 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'a' + string[i+1:] in H[temp]:
                    return 1
        if string[i] == 'c':
            temp = (tmp - 3 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'b' + string[i+1:] in H[temp]:
                    return 1
            temp = (tmp - 2 * 3 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'a' + string[i+1:] in H[temp]:
                    return 1
    return 0

f = sys.stdin
n, m = [int(x) for x in f.readline().split(' ')]
H = {}
for i in xrange(n):
    string = f.readline().strip()
    tmp = calc(string)
    if tmp in H:
        H[tmp].append(string)
    else:
        H[tmp] = [string]
for j in xrange(m):
    string = f.readline().strip()
    if check(string):
        print("YES")
    else:
        print("NO")


import sys

MAXN = 10 ** 9 + 7

def calc(string):
    ans = 0
    for ch in string:
        ans = ans * 4 + ord(ch) - 96
    return ans

def check(string):
    tmp = calc(string)
    for i in xrange(len(string)):
        if string[i] == 'a':
            temp = (tmp + 4 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'b' + string[i+1:] in H[temp]:
                    return 1
            temp = (tmp + 2 * 4 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'c' + string[i+1:] in H[temp]:
                    return 1
        if string[i] == 'b':
            temp = (tmp + 4 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'c' + string[i+1:] in H[temp]:
                    return 1
            temp = (tmp - 4 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'a' + string[i+1:] in H[temp]:
                    return 1
        if string[i] == 'c':
            temp = (tmp - 4 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'b' + string[i+1:] in H[temp]:
                    return 1
            temp = (tmp - 2 * 4 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'a' + string[i+1:] in H[temp]:
                    return 1
    return 0

f = sys.stdin
n, m = [int(x) for x in f.readline().split(' ')]
H = {}
for i in xrange(n):
    string = f.readline().strip()
    tmp = calc(string) % MAXN
    if tmp in H:
        H[tmp].append(string)
    else:
        H[tmp] = [string]
for j in xrange(m):
    string = f.readline().strip()
    if check(string):
        print("YES")
    else:
        print("NO")


import sys

def calc(string):
    ans = 0
    for ch in string:
        ans = ans * 4 + ord(ch) - 96
    return ans

def check(string):
    tmp = calc(string)
    order = 1
    for i in xrange(len(string)-1, -1, -1):
        if string[i] == 'a':
            temp = tmp + order
            if temp in H:
                return 1
            temp = tmp + 2 * order
            if temp in H:
                return 1
        if string[i] == 'b':
            temp = tmp + order
            if temp in H:
                return 1
            temp = tmp - order
            if temp in H:
                return 1
        if string[i] == 'c':
            temp = tmp - order
            if temp in H:
                return 1
            temp = tmp - 2 * order
            if temp in H:
                return 1
        order *= 4
    return 0

f = sys.stdin
n, m = [int(x) for x in f.readline().split(' ')]
H = set()
for i in xrange(n):
    string = f.readline().strip()
    H.add(calc(string))
for j in xrange(m):
    string = f.readline().strip()
    if check(string):
        print("YES")
    else:
        print("NO")


import sys

MAXN = 10 ** 9 + 7

def calc(string):
    ans = 0
    for ch in string:
        ans = (ans * 4 + ord(ch) - 96) % MAXN
    return ans

def check(string):
    tmp = calc(string)
    order = 1
    for i in xrange(len(string)-1, -1, -1):
        if string[i] == 'a':
            temp = (tmp + order) % MAXN
            if temp in H:
                if string[:i] + 'b' + string[i+1:] in H[temp]:
                    return 1
            temp = (tmp + 2 * order) % MAXN
            if temp in H:
                if string[:i] + 'c' + string[i+1:] in H[temp]:
                    return 1
        if string[i] == 'b':
            temp = (tmp + order) % MAXN
            if temp in H:
                if string[:i] + 'c' + string[i+1:] in H[temp]:
                    return 1
            temp = (tmp - order) % MAXN
            if temp in H:
                if string[:i] + 'a' + string[i+1:] in H[temp]:
                    return 1
        if string[i] == 'c':
            temp = (tmp - order) % MAXN
            if temp in H:
                if string[:i] + 'b' + string[i+1:] in H[temp]:
                    return 1
            temp = (tmp - 2 * order) % MAXN
            if temp in H:
                if string[:i] + 'a' + string[i+1:] in H[temp]:
                    return 1
        order = (order * 4) % MAXN
    return 0

f = sys.stdin
n, m = [int(x) for x in f.readline().split(' ')]
H = {}
for i in xrange(n):
    string = f.readline().strip()
    tmp = calc(string)
    if tmp in H:
        H[tmp].append(string)
    else:
        H[tmp] = [string]
for j in xrange(m):
    string = f.readline().strip()
    if check(string):
        print("YES")
    else:
        print("NO")


import sys

def calc(string):
    ans = 0
    for ch in string:
        ans = ans * 4 + ord(ch) - 96
    return ans

def check(string):
    tmp = calc(string)
    for i in xrange(len(string)):
        if string[i] == 'a':
            if tmp + 4 ** (len(string) - 1 - i) in H:
                return 1
            if tmp + 2 * 4 ** (len(string) - 1 - i) in H:
                return 1
        if string[i] == 'b':
            if tmp + 4 ** (len(string) - 1 - i) in H:
                return 1
            if tmp - 4 ** (len(string) - 1 - i) in H:
                return 1
        if string[i] == 'c':
            if tmp - 4 ** (len(string) - 1 - i) in H:
                return 1
            if tmp - 2 * 4 ** (len(string) - 1 - i) in H:
                return 1
    return 0

f = sys.stdin
n, m = [int(x) for x in f.readline().split(' ')]
H = set()
for i in xrange(n):
    string = f.readline().strip()
    H.add(calc(string))
for j in xrange(m):
    string = f.readline().strip()
    if check(string):
        print("YES")
    else:
        print("NO")


import sys

MAXN = 10 ** 9 + 7

def calc(string):
    ans = 0
    for ch in string:
        ans = ans * 4 + ord(ch) - 96
    return ans

def check(string):
    tmp = calc(string)
    for i in xrange(len(string)):
        if string[i] == 'a':
            temp = (tmp + 4 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'b' + string[i+1:] in H[temp]:
                    return 1
            temp = (tmp + 2 * 4 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'c' + string[i+1:] in H[temp]:
                    return 1
        if string[i] == 'b':
            temp = (tmp + 4 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'c' + string[i+1:] in H[temp]:
                    return 1
            temp = (tmp - 4 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'a' + string[i+1:] in H[temp]:
                    return 1
        if string[i] == 'c':
            temp = (tmp - 4 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'a' + string[i+1:] in H[temp]:
                    return 1
            temp = (tmp + 2 * 4 ** (len(string) - 1 - i)) % MAXN
            if temp in H:
                if string[:i] + 'b' + string[i+1:] in H[temp]:
                    return 1
    return 0

f = sys.stdin
n, m = [int(x) for x in f.readline().split(' ')]
H = {}
for i in xrange(n):
    string = f.readline().strip()
    tmp = calc(string) % MAXN
    if tmp in H:
        H[tmp].append(string)
    else:
        H[tmp] = [string]
for j in xrange(m):
    string = f.readline().strip()
    if check(string):
        print("YES")
    else:
        print("NO")


using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Policy;

class ProblemC {
    static string inputFileName = "../../input.txt";
    static StreamReader fileReader;
    static string[] inputTokens;
    static int curInputTokenIndex;
    static string NextToken() {
        if (inputTokens == null || curInputTokenIndex >= inputTokens.Length) {
            if (Type.GetType("HaitaoLocal") != null) {
                if (fileReader == null) {
                    fileReader = new StreamReader(inputFileName);
                }
                inputTokens = fileReader.ReadLine().Split();
            } else {
                inputTokens = Console.ReadLine().Split();
            }
            curInputTokenIndex = 0;
        }
        return inputTokens[curInputTokenIndex++];
    }
    static int ReadInt() {
        return Int32.Parse(NextToken());
    }
    static string ReadString() {
        return NextToken();
    }
    static long ReadLong() {
        return Int64.Parse(NextToken());
    }
    static int[] ReadIntArray(int length) {
        int[] ret = new int[length];
        for (int i = 0; i < length; i++) {
            ret[i] = ReadInt();
        }
        return ret;
    }
    static string[] ReadStringArray(int length) {
        string[] ret = new string[length];
        for (int i = 0; i < length; i++) {
            ret[i] = ReadString();
        }
        return ret;
    }
    static long[] ReadLongArray(int length) {
        long[] ret = new long[length];
        for (int i = 0; i < length; i++) {
            ret[i] = ReadLong();
        }
        return ret;
    }

    public static void Main(string[] args) {

        int N = ReadInt();
        int M = ReadInt();
        int[] a = new int[M];
        int[] b = new int[M];
        for (int m = 0; m < M; m++) {
            a[m] = ReadInt();
            b[m] = ReadInt();
        }

        int highest = -1000000000;

        for (int m = 0; m < M-1; m++) {
            if(Math.Abs(b[m+1]-b[m])>a[m+1]-a[m])
            {Console.WriteLine("IMPOSSIBLE"); return;}

            int d = a[m+1]-a[m];
            int x = ((Math.Min(b[m], b[m + 1]) + d) + Math.Max(b[m], b[m + 1])) / 2;
            highest = Math.Max(highest, x);
        }

        int y = b[0] + a[0] - 1;
        int z = b[M - 1] + (N - a[M - 1]);

        highest = Math.Max(highest, y);
        highest = Math.Max(highest, z);

        Console.WriteLine(highest);

    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Active
{
	public class Day
	{
		public int DayNumb { get; set; }

		public int Height { get; set; }

		public Day(int dayNumb, int height)
		{
			DayNumb = dayNumb;
			Height = height;
		}
	}

	public class Solver
	{
		//StreamReader sr = new StreamReader("input.txt");

		private int _n, _m;
		private readonly List<Day> _days = new List<Day>();

		public void Solve()
		{
			// Reading...
			var nm = Console.ReadLine().SplitToStringList();
			_n = nm[0].ToInt();
			_m = nm[1].ToInt();
			for (int i = 0; i < _m; i++)
			{
				var dh = Console.ReadLine().SplitToStringList();
				_days.Add(new Day(dh[0].ToInt(), dh[1].ToInt()));
			}

			// Resolving...
			int ans = 0;
			_days.Sort((x, y) => x.DayNumb.CompareTo(y.DayNumb));
			for (int i = 0; i < _m - 1; i++)
			{
				var today = _days[i];
				var tomorrow = _days[i + 1];
				if (Abs(tomorrow.Height - today.Height) > Abs(tomorrow.DayNumb - today.DayNumb))
				{
					Console.WriteLine("IMPOSSIBLE");
					return;
				}
				ans = Max(ans, Max(today.Height, tomorrow.Height) + Abs(Abs(tomorrow.Height - today.Height) - Abs(tomorrow.DayNumb - today.DayNumb)) / 2);
			}
			ans = Max(ans, _days[_m - 1].Height + _n - _days[_m - 1].DayNumb);
			ans = Max(ans, _days[0].Height + _days[0].DayNumb - 1);
			Console.WriteLine(ans);
		}

		private int Abs(int x)
		{
			return Math.Abs(x);
		}

		private int Max(int x, int y)
		{
			return Math.Max(x, y);
		}

	}

	class Program
	{
		static void Main(string[] args)
		{
			new Solver().Solve();
		}
	}

	public static class Helper
	{
		public static T Convert<T>(this string s)
		{
			try
			{
				return (T)System.Convert.ChangeType(s, typeof (T));
			}
			catch (Exception ex)
			{
				throw new FormatException(String.Format("Не получилось конвертнуть в {0}", typeof(T)));
			}
		}

		public static List<string> SplitToStringList(this string s)
		{
			return s
				.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries)
				.ToList();
		}

		public static int ToInt(this string s)
		{
			return int.Parse(s);
		}

		public static double ToDouble(this string s)
		{
			return double.Parse(s);
		}
	}
}


using System;

namespace TouristsNotes
{
    partial class TouristsNotes
    {
        static void Main(string[] args)
        {
            int n, m;
            int daysDiff, heightsDiff;
            int current, max;
            int[] days;
            int[] heights;
            bool answer = true;

            n = NextInt();
            m = NextInt();

            days = new int[n];
            heights = new int[n];

            for (int i = 0; i < m; i++)
            {
                days[i] = NextInt();
                heights[i] = NextInt();
            }

            max = days[0] == 0 ? heights[0] : (days[0] - 1) + heights[0];

            for (int i = 1; i < m; i++)
            {
                daysDiff = days[i] - days[i - 1];
                heightsDiff = Math.Abs(heights[i] - heights[i - 1]);

                if (heightsDiff > daysDiff)
                {
                    answer = false;
                    break;
                }

                daysDiff -= heightsDiff;
                current = (daysDiff / 2) + Math.Max(heights[i], heights[i - 1]);

                if (current > max)
                    max = current;
            }

            Console.WriteLine(answer ? max.ToString() : "IMPOSSIBLE");
        }
    }

    partial class TouristsNotes
    {
        static string[] tokens = new string[0];
        static int cur_token = 0;

        static void ReadArray(char sep)
        {
            cur_token = 0;
            tokens = Console.ReadLine().Split(sep);
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int NextInt()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return int.Parse(tokens[cur_token++]);
        }

        static long NextLong()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return long.Parse(tokens[cur_token++]);
        }

        static double NextDouble()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return double.Parse(tokens[cur_token++]);
        }

        static decimal NextDecimal()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return decimal.Parse(tokens[cur_token++]);
        }

        static string NextToken()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return tokens[cur_token++];
        }

        static string ReadLine()
        {
            return Console.ReadLine();
        }
    }
}


using System;

namespace TouristsNotes
{
    partial class TouristsNotes
    {
        static void Main(string[] args)
        {
            int n, m;
            int daysDiff, heightsDiff;
            int current, max;
            int previousDay, previousHeight;
            int currentDay, currentHeight;
            bool answer = true;

            n = NextInt();
            m = NextInt();

            previousDay = NextInt();
            previousHeight = NextInt();

            max = previousDay == 0 ? previousHeight : (previousDay - 1) + previousHeight;

            for (int i = 1; i < m; i++)
            {
                currentDay = NextInt();
                currentHeight = NextInt();

                daysDiff = currentDay - previousDay;
                heightsDiff = Math.Abs(currentHeight - previousHeight);

                if (heightsDiff > daysDiff)
                {
                    answer = false;
                    break;
                }

                daysDiff -= heightsDiff;
                current = (daysDiff / 2) + Math.Max(currentHeight, previousHeight);

                if (current > max)
                    max = current;

                previousDay = currentDay;
                previousHeight = currentHeight;
            }

            if (answer && previousDay != n)
            {
                current = (n - previousDay) + previousHeight;

                if (current > max)
                    max = current;
            }

            Console.WriteLine(answer ? max.ToString() : "IMPOSSIBLE");
        }
    }

    partial class TouristsNotes
    {
        static string[] tokens = new string[0];
        static int cur_token = 0;

        static void ReadArray(char sep)
        {
            cur_token = 0;
            tokens = Console.ReadLine().Split(sep);
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int NextInt()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return int.Parse(tokens[cur_token++]);
        }

        static long NextLong()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return long.Parse(tokens[cur_token++]);
        }

        static double NextDouble()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return double.Parse(tokens[cur_token++]);
        }

        static decimal NextDecimal()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return decimal.Parse(tokens[cur_token++]);
        }

        static string NextToken()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return tokens[cur_token++];
        }

        static string ReadLine()
        {
            return Console.ReadLine();
        }
    }
}


using System;

namespace TouristsNotes
{
    partial class TouristsNotes
    {
        static void Main(string[] args)
        {
            long n, m;
            long daysDiff, heightsDiff;
            long current, max;
            long[] days;
            long[] heights;
            bool answer = true;

            n = NextInt();
            m = NextInt();

            days = new long[n];
            heights = new long[n];

            for (long i = 0; i < m; i++)
            {
                days[i] = NextInt();
                heights[i] = NextInt();
            }

            max = days[0] == 0 ? heights[0] : (days[0] - 1) + heights[0];

            for (long i = 1; i < m; i++)
            {
                daysDiff = days[i] - days[i - 1];
                heightsDiff = Math.Abs(heights[i] - heights[i - 1]);

                if (heightsDiff > daysDiff)
                {
                    answer = false;
                    break;
                }

                daysDiff -= heightsDiff;
                current = (daysDiff / 2) + Math.Max(heights[i], heights[i - 1]);

                if (current > max)
                    max = current;
            }

            Console.WriteLine(answer ? max.ToString() : "IMPOSSIBLE");
        }
    }

    partial class TouristsNotes
    {
        static string[] tokens = new string[0];
        static int cur_token = 0;

        static void ReadArray(char sep)
        {
            cur_token = 0;
            tokens = Console.ReadLine().Split(sep);
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int NextInt()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return int.Parse(tokens[cur_token++]);
        }

        static long NextLong()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return long.Parse(tokens[cur_token++]);
        }

        static double NextDouble()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return double.Parse(tokens[cur_token++]);
        }

        static decimal NextDecimal()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return decimal.Parse(tokens[cur_token++]);
        }

        static string NextToken()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return tokens[cur_token++];
        }

        static string ReadLine()
        {
            return Console.ReadLine();
        }
    }
}


using System;

namespace TouristsNotes
{
    partial class TouristsNotes
    {
        static void Main(string[] args)
        {
            long n, m;
            long daysDiff, heightsDiff;
            long current, max;
            long[] days;
            long[] heights;
            bool answer = true;

            n = NextInt();
            m = NextInt();

            days = new long[n];
            heights = new long[n];

            for (long i = 0; i < m; i++)
            {
                days[i] = NextInt();
                heights[i] = NextInt();
            }

            max = days[0] == 0 ? heights[0] : (days[0] - 1) + heights[0];

            for (long i = 1; i < m; i++)
            {
                daysDiff = days[i] - days[i - 1];
                heightsDiff = Math.Abs(heights[i] - heights[i - 1]);

                if (heightsDiff > daysDiff)
                {
                    answer = false;
                    break;
                }

                daysDiff -= heightsDiff;
                current = daysDiff / 2;

                if (current > max)
                    max = current;
            }

            Console.WriteLine(answer ? max.ToString() : "IMPOSSIBLE");
        }
    }

    partial class TouristsNotes
    {
        static string[] tokens = new string[0];
        static int cur_token = 0;

        static void ReadArray(char sep)
        {
            cur_token = 0;
            tokens = Console.ReadLine().Split(sep);
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int NextInt()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return int.Parse(tokens[cur_token++]);
        }

        static long NextLong()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return long.Parse(tokens[cur_token++]);
        }

        static double NextDouble()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return double.Parse(tokens[cur_token++]);
        }

        static decimal NextDecimal()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return decimal.Parse(tokens[cur_token++]);
        }

        static string NextToken()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return tokens[cur_token++];
        }

        static string ReadLine()
        {
            return Console.ReadLine();
        }
    }
}


namespace topCoder
{
	using System;
	using System.Collections.Generic;

	class p3
	{
		static void Main(string[] args)
		{
			p3 o = new p3();
			o.foo();
		}
		public void foo()
		{
			string[] sp = Console.ReadLine().Split(' ');
			int n = int.Parse(sp[0]);
			int m = int.Parse(sp[1]);

			int[] d = new int[m];
			int[] h = new int[m];
			for (int i = 0; i < m; i++)
			{
				sp = Console.ReadLine().Split(' ');
				d[i] = int.Parse(sp[0]);
				h[i] = int.Parse(sp[1]);
			}

			int ret = 0;
			for (int i = 1; i < m; i++)
			{
				int dh = Math.Abs(h[i - 1] - h[i]);
				int dd = Math.Abs(d[i - 1] - d[i]) - 1;

				if (dh < dd || dh == dd)
					ret = Math.Max(ret, ((dd - dh)/2) + Math.Max(h[i - 1], h[i]));
				else
				{
					Console.WriteLine("IMPOSSIBLE");
					return;
				}
			}

			ret = Math.Max(ret, h[0] + (d[0] - 1));
			ret = Math.Max(ret, h[m-1] + (m-d[m-1]));
			Console.WriteLine(ret);
		}
	}
}


namespace topCoder
{
	using System;
	using System.Collections.Generic;

	class p3
	{
		static void Main(string[] args)
		{
			p3 o = new p3();
			o.foo();
		}
		public void foo()
		{
			string[] sp = Console.ReadLine().Split(' ');
			int n = int.Parse(sp[0]);
			int m = int.Parse(sp[1]);

			int[] d = new int[m];
			int[] h = new int[m];
			for (int i = 0; i < m; i++)
			{
				sp = Console.ReadLine().Split(' ');
				d[i] = int.Parse(sp[0]);
				h[i] = int.Parse(sp[1]);
			}

			int ret = 0;
			for (int i = 1; i < m; i++)
			{
				int dh = Math.Abs(h[i - 1] - h[i]);
				int dd = Math.Abs(d[i - 1] - d[i]) - 1;

				if (dh < dd || dh == dd)
					ret = Math.Max(ret, ((dd - dh)/2) + Math.Max(h[i - 1], h[i]));
				else
				{
					Console.WriteLine("IMPOSSIBLE");
					return;
				}
			}

			ret = Math.Max(ret, h[0] + (d[0] - 1));
			ret = Math.Max(ret, h[m-1] + (n-d[m-1]));
			Console.WriteLine(ret);
		}
	}
}


namespace topCoder
{
	using System;
	using System.Collections.Generic;

	class p3
	{
		static void Main(string[] args)
		{
			p3 o = new p3();
			o.foo();
		}
		public void foo()
		{
			string[] sp = Console.ReadLine().Split(' ');
			int n = int.Parse(sp[0]);
			int m = int.Parse(sp[1]);

			int[] d = new int[m];
			int[] h = new int[m];
			for (int i = 0; i < m; i++)
			{
				sp = Console.ReadLine().Split(' ');
				d[i] = int.Parse(sp[0]);
				h[i] = int.Parse(sp[1]);
			}

			int ret = 0;
			for (int i = 1; i < m; i++)
			{
				int dh = Math.Abs(h[i - 1] - h[i]);
				int dd = Math.Abs(d[i - 1] - d[i]) - 1;

				if (dh < dd || dh == dd)
					ret = Math.Max(ret, ((dd - dh + 1)/2) + Math.Max(h[i - 1], h[i]));
				else
				{
					Console.WriteLine("IMPOSSIBLE");
					return;
				}
			}

			ret = Math.Max(ret, h[0] + (d[0] - 1));
			ret = Math.Max(ret, h[m-1] + (n-d[m-1]));
			Console.WriteLine(ret);
		}
	}
}


namespace topCoder
{
	using System;
	using System.Collections.Generic;

	class p3
	{
		static void Main(string[] args)
		{
			p3 o = new p3();
			o.foo();
		}
		public void foo()
		{
			string[] sp = Console.ReadLine().Split(' ');
			int n = int.Parse(sp[0]);
			int m = int.Parse(sp[1]);

			int[] d = new int[m];
			int[] h = new int[m];
			for (int i = 0; i < m; i++)
			{
				sp = Console.ReadLine().Split(' ');
				d[i] = int.Parse(sp[0]);
				h[i] = int.Parse(sp[1]);
			}

			int ret = 0;
			for (int i = 1; i < m; i++)
			{
				int dh = Math.Abs(h[i - 1] - h[i]);
				int dd = Math.Abs(d[i - 1] - d[i]);

				if (dh < dd || dh == dd)
					ret = Math.Max(ret, ((dd - dh)/2) + Math.Max(h[i - 1], h[i]));
				else
				{
					Console.WriteLine("IMPOSSIBLE");
					return;
				}
			}

			ret = Math.Max(ret, h[0] + (d[0] - 1));
			ret = Math.Max(ret, h[m-1] + (n-d[m-1]));
			Console.WriteLine(ret);
		}
	}
}


namespace topCoder
{
	using System;
	using System.Collections.Generic;

	class p3
	{
		static void Main(string[] args)
		{
			p3 o = new p3();
			o.foo();
		}
		public void foo()
		{
			string[] sp = Console.ReadLine().Split(' ');
			int n = int.Parse(sp[0]);
			int m = int.Parse(sp[1]);

			int[] d = new int[m];
			int[] h = new int[m];
			for (int i = 0; i < m; i++)
			{
				sp = Console.ReadLine().Split(' ');
				d[i] = int.Parse(sp[0]);
				h[i] = int.Parse(sp[1]);
			}

			int ret = 0;
			for (int i = 1; i < m; i++)
			{
				int dh = Math.Abs(h[i - 1] - h[i]);
				int dd = Math.Abs(d[i - 1] - d[i]);

				if (dh < dd || dh == dd)
					ret = Math.Max(ret, ((dd - dh + 1)/2) + Math.Max(h[i - 1], h[i]));
				else
				{
					Console.WriteLine("IMPOSSIBLE");
					return;
				}
			}

			ret = Math.Max(ret, h[0] + (d[0] - 1));
			ret = Math.Max(ret, h[m-1] + (n-d[m-1]));
			Console.WriteLine(ret);
		}
	}
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Codeforces
{
	internal class Template
	{
		private static readonly Scanner cin = new Scanner();

		private static void Main()
		{
#if !ONLINE_JUDGE
			//Console.SetIn(new StreamReader(@"C:\CodeForces\input.txt"));
#endif
			new Template().Solve();
			Console.ReadLine();
		}

		private void Solve()
		{
			var n = cin.NextInt();
			var m = cin.NextInt();
			var best = int.MinValue;
			var d = new List<int>();
			var h = new List<int>();
			for (var i = 0; i < m; i++)
			{
				d.Add(cin.NextInt());
				h.Add(cin.NextInt());
				best = Math.Max(best, h[i]);
			}
			for (var i = 1; i < m; i++)
			{
				if (d[i] - d[i - 1] < Math.Abs(h[i] - h[i - 1]))
				{
					Console.WriteLine("IMPOSSIBLE");
					return;
				}
				var min = Math.Min(h[i], h[i - 1]);
				var max = Math.Max(h[i], h[i - 1]);
				var diff = max - min;
				var days = d[i] - d[i - 1] - 1;
				var leftDays = days - diff;
				var plusH = leftDays/2 + leftDays%2;
				var maxH = max + plusH;
				best = Math.Max(best, maxH);
			}
			best = Math.Max(best, h[0] + d[0] - 1);
			best = Math.Max(best, h.Last() + (n - d.Last()));
			Console.WriteLine(best);
		}
	}

	internal class Scanner
	{
		private string[] s = new string[0];
		private int i;
		private readonly char[] cs = { ' ' };

		public string NextString()
		{
			if (i < s.Length) return s[i++];
			var line = Console.ReadLine() ?? string.Empty;
			s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			i = 1;
			return s.First();
		}

		public double NextDouble()
		{
			return double.Parse(NextString());
		}

		public int NextInt()
		{
			return int.Parse(NextString());
		}

		public long NextLong()
		{
			return long.Parse(NextString());
		}
	}
}


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;

namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var n = sc.Integer();
            var m = sc.Integer();
            var p = new long[m];
            var q = new long[m];
            var map = new HashMap<long, long>();
            for (int i = 0; i < m; i++)
            {
                var a = sc.Integer() - 1;
                var v = sc.Integer();
                p[i] = a;
                q[i] = v;
                if (map.ContainsKey(a))
                {
                    if (map[a] != v)
                    {
                        IO.Printer.Out.WriteLine("IMPOSSIBLE");
                        return;
                    }
                }
                else map[a] = v;
            }
            var list = new List<KeyValuePair<long, long>>();
            foreach (var kv in map)
                list.Add(kv);
            list.Sort((l, r) => l.Key.CompareTo(r.Key));
            var max = list[0].Key + list[0].Value;
            var t = list.Count;
            for (int i = 1; i < t; i++)
            {
                var left = list[i - 1];
                var right = list[i];
                var dx = right.Key - left.Key;
                if (left.Value + dx < right.Value || left.Value > right.Value + dx)
                {
                    IO.Printer.Out.WriteLine("IMPOSSIBLE");
                    return;
                }
                var pp = (right.Value - left.Value + dx) / 2;
                max = Math.Max(left.Value + pp, max);
                Debug.WriteLine(max);
            }
            max = Math.Max(max, n - 1 - list[t - 1].Key + list[t - 1].Value);
            IO.Printer.Out.WriteLine(max);
        }
        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }
        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }
}

#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Text;
    using System.Globalization;
    public class Printer : StreamWriter
    {
        static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, IEnumerable<T> source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, IEnumerable<T> source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; }

        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

        public char[] Char(int n) { return enumerate(n, Char); }
        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
    }
}
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion

#region HashMap
class HashMap<K, V> : Dictionary<K, V>
{
    new public V this[K i]
    {
        get
        {
            V v;
            return TryGetValue(i, out v) ? v : base[i] = default(V);
        }
        set { base[i] = value; }
    }
}
#endregion


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;

namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var n = sc.Integer();
            var m = sc.Integer();
            var h = new int[n];
            for (int i = 0; i < n; i++)
                h[i] = int.MaxValue;
            var p = new int[m];
            var q = new int[m];
            for (int i = 0; i < m; i++)
            {
                var a = sc.Integer() - 1;
                var v = sc.Integer();
                h[a] = v;
                p[i] = a;
                q[i] = v;
                for (int j = a + 1; j < n; j++)
                    h[j] = Math.Min(v + (j - a), h[j]);
                for (int j = 1; j <= a; j++)
                    h[a - j] = Math.Min(v + j, h[a - j]);
                Debug.WriteLine(h.AsJoinedString());
            }
            for (int i = 0; i < m; i++)
            {
                var pos = p[i];
                if (h[pos] != q[i])
                {
                    IO.Printer.Out.WriteLine("IMPOSSIBLE");
                    return;
                }
            }
            for (int i = 1; i < n; i++)
                if (Math.Abs(h[i] - h[i - 1]) > 1)
                {
                    IO.Printer.Out.WriteLine("IMPOSSIBLE");
                    return;
                }
            IO.Printer.Out.WriteLine(h.Max());
        }
        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }
        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }
}

#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Text;
    using System.Globalization;
    public class Printer : StreamWriter
    {
        static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, IEnumerable<T> source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, IEnumerable<T> source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; }

        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

        public char[] Char(int n) { return enumerate(n, Char); }
        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
    }
}
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Task3
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();

            long n = Convert.ToInt64(line.Substring(0, line.IndexOf(' ')));
            line = line.Substring(line.IndexOf(' ') + 1);
            int m = Convert.ToInt32(line);

            var d = new List<long>();
            var h = new List<long>();

            bool b = false;

            for (long i = 0; i < m; i++)
            {
                line = Console.ReadLine();

                d.Add(Convert.ToInt64(line.Substring(0, line.IndexOf(' '))));
                line = line.Substring(line.IndexOf(' ') + 1);
                h.Add(Convert.ToInt64(line));
            }
            for (int i = 0; i < m - 1; i++)
            {
                if (Math.Abs(h[i + 1] - h[i]) > (d[i + 1] - d[i]))
                {
                    Console.WriteLine("IMPOSSIBLE");
                    b = true;
                    break;
                }
            }

            long max = 0;

            if (!b)
            {
                max = h[m - 1] + (n - d[m - 1]);

                long temp = h[0] + d[0] - 1;

                if (max < temp)
                {
                    max = temp;
                }

                for (int i = 0; i < m; i++)
                {
                    if (max < h[i])
                    {
                        max = h[i];
                    }
                }

                for (int i = 0; i < m - 1; i++)
                {
                    if (h[i] <= h[i + 1])
                    {
                        temp = (long)((d[i + 1] - (d[i] + (h[i + 1] - h[i]))) / 2) + h[i + 1];

                        if (max < temp)
                        {
                            max = temp;
                        }
                    }
                    else
                    {
                        temp = (long)(((d[i + 1] - (h[i] - h[i + 1])) - d[i]) / 2) + h[i];

                        if (max < temp)
                        {
                            max = temp;
                        }
                    }
                }
                Console.WriteLine(max);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Task3
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();

            long n = Convert.ToInt64(line.Substring(0, line.IndexOf(' ')));
            line = line.Substring(line.IndexOf(' ') + 1);
            int m = Convert.ToInt32(line);

            var d = new List<long>();
            var h = new List<long>();

            bool b = false;

            for (long i = 0; i < m; i++)
            {
                line = Console.ReadLine();

                d.Add(Convert.ToInt64(line.Substring(0, line.IndexOf(' '))));
                line = line.Substring(line.IndexOf(' ') + 1);
                h.Add(Convert.ToInt64(line));
            }
            for (int i = 0; i < m - 1; i++)
            {
                if (Math.Abs((float)(h[i + 1] - h[i]) / (float)(d[i + 1] - d[i])) > 1.0f)
                {
                    Console.WriteLine("IMPOSSIBLE");
                    b = true;
                    break;
                }
            }

            long max = 0;

            if (!b)
            {
                max = h[m - 1] + (n - d[m - 1]);

                long temp = h[0] + d[0] - 1;

                if (max < temp)
                {
                    max = temp;
                }

                for (int i = 0; i < m; i++)
                {
                    if (max < h[i])
                    {
                        max = h[i];
                    }
                }

                for (int i = 0; i < m - 1; i++)
                {
                    if (h[i] <= h[i + 1])
                    {
                        temp = (long)(d[i + 1] - (d[i] + (h[i + 1] - h[i]))) / 2;

                        if (max < temp)
                        {
                            max = temp;
                        }
                    }
                    else
                    {
                        temp = (long)(d[i] - (d[i + 1] + (h[i] - h[i + 1]))) / 2;

                        if (max < temp)
                        {
                            max = temp;
                        }
                    }
                }
                Console.WriteLine(max);
            }
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace Tourists_Notes
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();
            int m = Next();

            var d = new int[n];
            var h = new int[n];
            for (int i = 0; i < n; i++)
            {
                d[i] = Next();
                h[i] = Next();
            }

            long max = 0;

            for (int i = 1; i < n; i++)
            {
                long x = (h[i] - h[i - 1] - d[i] + d[i - 1])/2;
                if (x < d[i - 1] || x > d[i])
                {
                    writer.WriteLine("IMPOSSIBLE");
                    writer.Flush();
                    return;
                }
                long hh = (h[i] + h[i - 1] - d[i] - d[i - 1])/2;
                if (max < hh)
                    max = hh;
            }

            writer.WriteLine("{0}", max);
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace Tourists_Notes
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();
            int m = Next();

            var d = new int[m];
            var h = new int[m];
            for (int i = 0; i < m; i++)
            {
                d[i] = Next();
                h[i] = Next();
            }

            long max = h[0];

            for (int i = 1; i < m; i++)
            {
                long x = (h[i] - h[i - 1] + d[i] + d[i - 1])/2;
                if (x < d[i - 1] || x > d[i])
                {
                    writer.WriteLine("IMPOSSIBLE");
                    writer.Flush();
                    return;
                }
                long hh = (h[i] + h[i - 1] + d[i] - d[i - 1])/2;
                if (max < hh)
                    max = hh;
            }

            if (d[0] != 1)
            {
                long hh = -1 + d[0] + h[0];
                if (max < hh)
                    max = hh;
            }
            if (d[m - 1] != n)
            {
                long hh = n - d[m - 1] + h[m - 1];
                if (max < hh)
                    max = hh;
            }

            writer.WriteLine("{0}", max);
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace Tourists_Notes
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();
            int m = Next();

            var d = new int[m];
            var h = new int[m];
            for (int i = 0; i < m; i++)
            {
                d[i] = Next();
                h[i] = Next();
            }

            long max = 0;

            for (int i = 1; i < m; i++)
            {
                long x = (h[i] - h[i - 1] + d[i] + d[i - 1])/2;
                if (x < d[i - 1] || x > d[i])
                {
                    writer.WriteLine("IMPOSSIBLE");
                    writer.Flush();
                    return;
                }
                long hh = (h[i] + h[i - 1] + d[i] - d[i - 1])/2;
                if (max < hh)
                    max = hh;
            }

            if (d[0] != 1)
            {
                long hh = -1 + d[0] + h[0];
                if (max < hh)
                    max = hh;
            }
            if (d[m - 1] != n)
            {
                long hh = n - d[m - 1] + h[m - 1];
                if (max < hh)
                    max = hh;
            }

            writer.WriteLine("{0}", max);
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace Tourists_Notes
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();
            int m = Next();

            var d = new int[m];
            var h = new int[m];
            for (int i = 0; i < m; i++)
            {
                d[i] = Next();
                h[i] = Next();
            }

            long max = 0;

            for (int i = 1; i < m; i++)
            {
                long x = (h[i] - h[i - 1] + d[i] + d[i - 1])/2;
                if (x < d[i - 1] || x > d[i])
                {
                    writer.WriteLine("IMPOSSIBLE");
                    writer.Flush();
                    return;
                }
                long hh = (h[i] + h[i - 1] + d[i] - d[i - 1])/2;
                if (max < hh)
                    max = hh;
            }

            writer.WriteLine("{0}", max);
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public PairVariable()
    {
        a = b = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
    }
    public PairVariable(int a, int b)
    {
        this.a = a;
        this.b = b;
    }
    public int CompareTo(PairVariable pv)
    {
        if (this.a > pv.a)
        {
            return 1;
        }
        else if (this.a < pv.a)
        {
            return -1;
        }
        else
        {
            if (this.b >= pv.b)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
    }

}
namespace ConsoleApplication254
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            int m = int.Parse(ss[1]);
            PairVariable[] p = new PairVariable[m];
            for (int i = 0; i < m; i++)
            {
                p[i] = new PairVariable(Console.ReadLine());
            }
            if (n == 1 && m == 1)
            {
                Console.WriteLine(p[0].b);
                return;
            }
            for (int i = 0; i < m - 1; i++)
            {
                if (Math.Abs(p[i].a - p[i + 1].a) < Math.Abs(p[i].b - p[i + 1].b))
                {
                    Console.WriteLine("IMPOSSIBLE");
                    return;
                }
            }
            List<int> ans = new List<int>();
            if (p[0].a != 1)
            {
                ans.Add(p[0].b + p[0].a - 1);
            }
            if (p[m - 1].a != n)
            {
                ans.Add(p[m - 1].b + (n - p[m - 1].a));
            }
            for (int i = 0; i < m - 1; i++)
            {
                ans.Add(Math.Max(p[i].b,p[i+1].b)+(Math.Abs(p[i].a - p[i + 1].a) - Math.Abs(p[i].b - p[i + 1].b))/2);
            }
            ans.Sort();
            Console.WriteLine(ans[ans.Count-1]);

        }
    }
}/*using System;
using System.Collections.Generic;
using System.Text;

namespace chislo
{
    class Program
    {
        static void Main(string[] args)
        {int sch = 0;
            string[] s = Console.ReadLine().Split(' ');
            long n = Convert.ToInt64(s[0]);
            long l1 = Convert.ToInt64(s[1]);
            long r1 = Convert.ToInt64(s[2]);
            List<long> l = new List<long>(); if (n == 0) Console.WriteLine(0);
            else
                if (n == 1)
                {
                    if (l1 <= 2 && r1 >= 2) Console.WriteLine(1);
                    else
                        Console.WriteLine(0);
                }
                else
            {
                for (int i = 0; n > 1; i++)
                {
                    l.Add(n); n /= 2;
                }
                string c = Convert.ToString(l[l.Count - 1] / 2);
                string c1 = Convert.ToString(l[l.Count - 1] % 2);
                string str = (c + c1 + c);
                for (int i = l.Count - 2; i >= 0; i--)
                {
                    c1 = Convert.ToString(l[i] % 2);
                    str += c1 + str;
                }
                Console.WriteLine(str);

                /*for (long i = l1 - 1; i < r1; i++)
                {
                    if (str[i] == '1') sch++;
                }
                 Console.WriteLine(str);
                Console.WriteLine(sch);

            }

        }
    }
}*/


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
			string textBox1 = Console.ReadLine();
 		    string textBox2="";//= Console.ReadLine();
           /* char[] arr;
            arr = num.ToCharArray(0, num.Length);
           */
           /* char[] arr2;
            arr2 = num.ToCharArray(0, num.Length);
*/
           int len = textBox1.Length;
            int beg ;
            beg =Convert.ToInt32( Math.Pow(2, len))-1;
            int end = beg*2;
            int ser =(end-beg+1)/2;
            char[] first = new char[len];
            int i = 0;

            while (i < len)
            {
                first[i] = textBox1[i];
                i++;
            }
            i = 0;
            while (i < len)
            {
                if(first[i]=='4')
                {
                    end = end - ser;
                    ser = ser / 2;
                }
                else
                {
                    beg = beg + ser;
                    ser = ser / 2;
                }

                i++;

            }
           // label1.Text = Convert.ToString(beg);

			Console.WriteLine(Convert.ToString(beg));

         }
    }
}


using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            long n,m,max=0,flag=0;
            string[] lines = Console.ReadLine().Split(' ');
            n= long.Parse(lines[0]);
            m= long.Parse(lines[1]);
            long[,] mas;
            mas=new long [m,2];
            string[] ll = Console.ReadLine().Split(' ');
            mas[0,0]=long.Parse(ll[0]);
            mas[0,1]=long.Parse(ll[1]);
            for(long j=1;j<m;j++)
            {
                 string[] l = Console.ReadLine().Split(' ');
                 mas[j,0]=long.Parse(l[0]);
                 mas[j,1]=long.Parse(l[1]);
                 if( ((mas[j,0]-mas[j-1,0])<(mas[j,1]-mas[j-1,1]))||((mas[j,0]-mas[j-1,0])<(mas[j-1,1]-mas[j,1])) )
                 {
                     flag=1;
                 }
            }

            if(flag==0)
            {
                long m1=0;
               for(long j=0;j<(m-1);j++)
                {
                  m1=mas[j+1,1]+(mas[j+1,0]-mas[j,0]-mas[j+1,1]+mas[j,1])/2;
                  if(max<m1)
                   max=m1;
                }

               Console.WriteLine(max);
            }
            else
               Console.WriteLine("IMPOSSIBLE");

        }
    }
}


using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            long n,m,max=0,flag=0;
            string[] lines = Console.ReadLine().Split(' ');
            n= long.Parse(lines[0]);
            m= long.Parse(lines[1]);
            long[,] mas;
            mas=new long [m,2];
            string[] ll = Console.ReadLine().Split(' ');
            mas[0,0]=long.Parse(ll[0]);
            mas[0,1]=long.Parse(ll[1]);
            for(long j=1;j<m;j++)
            {
                 string[] l = Console.ReadLine().Split(' ');
                 mas[j,0]=long.Parse(l[0]);
                 mas[j,1]=long.Parse(l[1]);
                 if( ((mas[j,0]-mas[j-1,0])<(mas[j,1]-mas[j-1,1]))||((mas[j,0]-mas[j-1,0])<(mas[j-1,1]-mas[j,1])) )
                 {
                     flag=1;
                 }
            }

            if(flag==0)
            {
                long m1=mas[0,1]+n-mas[0,0];
                if(m1<(mas[0,1]+mas[0,0]-1))
                 m1=mas[0,1]+mas[0,0]-1;
               for(long j=0;j<(m-1);j++)
                {
                  m1=mas[j+1,1]+(mas[j+1,0]-mas[j,0]-mas[j+1,1]+mas[j,1])/2;
                  if(max<m1)
                   max=m1;
                }
                if(max<m1)
                   max=m1;
               Console.WriteLine(max);
            }
            else
               Console.WriteLine("IMPOSSIBLE");

        }
    }
}


using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            long n,m,max=0,flag=0;
            string[] lines = Console.ReadLine().Split(' ');
            n= long.Parse(lines[0]);
            m= long.Parse(lines[1]);
            long[,] mas;
            mas=new long [m,2];
            string[] ll = Console.ReadLine().Split(' ');
            mas[0,0]=long.Parse(ll[0]);
            mas[0,1]=long.Parse(ll[1]);
            for(long j=1;j<m;j++)
            {
                 string[] l = Console.ReadLine().Split(' ');
                 mas[j,0]=long.Parse(l[0]);
                 mas[j,1]=long.Parse(l[1]);
                 if( ((mas[j,0]-mas[j-1,0])<(mas[j,1]-mas[j-1,1]))||((mas[j,0]-mas[j-1,0])<(mas[j-1,1]-mas[j,1])) )
                 {
                     flag=1;
                 }
            }

            if(flag==0)
            {
                long m1=mas[0,1]+n-mas[0,0];
                max=mas[0,1]+mas[0,0]-1;
               for(long j=0;j<(m-1);j++)
                {
                  m1=mas[j+1,1]+(mas[j+1,0]-mas[j,0]-mas[j+1,1]+mas[j,1])/2;
                  if(max<m1)
                   max=m1;
                }
                if(max<m1)
                   max=m1;
               Console.WriteLine(max);
            }
            else
               Console.WriteLine("IMPOSSIBLE");

        }
    }
}