CodeEff/ECCO huggingface dataset:
# Original solution
n,x=list(map(int,input().split()))
l=[1]
for i in range(50): l+=[l[-1]*2+3]
from functools import lru_cache
@lru_cache(None)
def f(n,x):
  return int(x>0) if n<1 else f(n-1,l[n-1])+1+f(n-1,x-l[n-1]-2) if x>l[n]//2 else f(n-1,x-1)
print((f(n,x)))

# Optimized solution
n,x=list(map(int,input().split()))
a,p=[1],[1]
for i in range(50): a+=[a[i]*2+3]; p+=[p[i]*2+1]
def f(n,x):
  return int(x>0) if n<1 else p[n-1]+1+f(n-1,x-2-a[n-1]) if x>a[n]//2 else f(n-1,x-1)
print((f(n,x)))
# Original solution
# -*- coding: utf-8 -*-

N, X = list(map(int, input().split()))

L, P = [1], [1]
for i in range(N - 1):
    L.append(L[-1] * 2 + 3)
    P.append(P[-1] * 2 + 1)


def countPatty(N, X):
    if N == 0:
        return 1 if X >= 1 else 0
    elif X <= 1:
        return 0
    elif 1 < X <= L[N - 1] + 1:
        return countPatty(N - 1, X - 1)
    elif L[N - 1] + 1 < X:
        return P[N - 1] + 1 + countPatty(N - 1, X - (L[N - 1] + 2))


print((countPatty(N, X)))


# Optimized solution
N, X = list(map(int, input().split()))
L, P = [1], [1]
for _ in range(N - 1):
    L.append(L[-1] * 2 + 3)
    P.append(P[-1] * 2 + 1)


def ans(N, X):
    if N == 0:
        return 1 if X >= 1 else 0
    elif X <= 1:
        return 0
    elif X <= L[N - 1] + 1:
        return ans(N - 1, X - 1)
    else:
        return P[N - 1] + 1 + ans(N - 1, X - (L[N - 1] + 2))


print((ans(N, X)))
# Original solution
def do(level,x):
    if x<=0: #1層も手を付けないとき
        return 0
    elif x>=whole[level]: #完食できるとき
        return patty[level]
    #それ以外、途中まで食べるときはlevel>=1の場合のみあり得る
    x-=1 #このとき1層目は必ずバンズ
    res=0 #食べたパティの総数を記録する
    if x>=whole[level-1]+1: #真ん中のパティまで到達できるとき
        x-=whole[level-1]+1
        res+=patty[level-1]+1
    return res+do(level-1,x)

n,x=list(map(int,input().split()))
whole=[1, 5, 13, 29, 61, 125, 253, 509, 1021, 2045, 4093, 8189, 16381, 32765, 65533, 131069, 262141, 524285, 1048573, 2097149, 4194301, 8388605, 16777213, 33554429, 67108861, 134217725, 268435453, 536870909, 1073741821, 2147483645, 4294967293, 8589934589, 17179869181, 34359738365, 68719476733, 137438953469, 274877906941, 549755813885, 1099511627773, 2199023255549, 4398046511101, 8796093022205, 17592186044413, 35184372088829, 70368744177661, 140737488355325, 281474976710653, 562949953421309, 1125899906842621, 2251799813685245, 4503599627370493]
patty=[1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863, 134217727, 268435455, 536870911, 1073741823, 2147483647, 4294967295, 8589934591, 17179869183, 34359738367, 68719476735, 137438953471, 274877906943, 549755813887, 1099511627775, 2199023255551, 4398046511103, 8796093022207, 17592186044415, 35184372088831, 70368744177663, 140737488355327, 281474976710655, 562949953421311, 1125899906842623, 2251799813685247]
print((do(n,x)))

# Optimized solution
def do(level,x):
    if x<=0: #1層も手を付けないとき
        return 0
    elif x>=whole[level]: #完食できるとき
        return patty[level]
    #それ以外、途中まで食べるときはlevel>=1の場合のみあり得る
    x-=1 #このとき1層目は必ずバンズ
    res=0 #食べたパティの総数を記録する
    if x>=whole[level-1]+1: #真ん中のパティまで到達できるとき
        x-=whole[level-1]+1
        res+=patty[level-1]+1
    return res+do(level-1,x)

n,x=list(map(int,input().split()))
whole=[1]+[0]*50
patty=[1]+[0]*50
for i in range(1,n+1):
    whole[i]=whole[i-1]*2+3
    patty[i]=patty[i-1]*2+1
print((do(n,x)))
# Original solution
from collections import defaultdict


def burger(lv, x):
    if d[(lv, x)] >= 0:
        return d[(lv, x)]

    if x < 1 or x > cnt[lv]:
        d[(lv, x)] = 0
        return d[(lv, x)]

    # base case
    if (lv, x) == (0, 1):
        d[(lv, x)] = 1
        return d[(lv, x)]

    half = (cnt[lv] - 1) // 2
    if x <= half:
        d[(lv, x)] = burger(lv - 1, x - 1)
        return d[(lv, x)]
    else:
        d[(lv, x)] = burger(lv - 1, half - 1) + 1 + burger(lv - 1, min(x - 1 - half, half - 1))
        return d[(lv, x)]


n, x = list(map(int, input().split()))
cnt = [1]
for lv in range(1, 50 + 1):
    cnt.append(cnt[-1] * 2 + 3)
d = defaultdict(lambda: -1)

print((burger(n, x)))
# print(d)


# Optimized solution
def burger(n, x):
    if x < 1:
        return 0

    # base case
    if (n, x) == (0, 1):
        return 1

    if x <= 1 + size[n - 1]:
        return burger(n - 1, x - 1)
    else:
        return p_num[n - 1] + 1 + burger(n - 1, min(x - 2 - size[n - 1], size[n - 1]))
    # x-2-sizeだと前lvバーガー+バンのことがあり、バンを外す


n, x = list(map(int, input().split()))
size, p_num = [1], [1]
for i in range(1, 50 + 1):
    size.append(size[-1] * 2 + 3)
    p_num.append(p_num[-1] * 2 + 1)

print((burger(n, x)))
# Original solution
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n,k = LI()
    h = IR(n)
    h.sort()
    ans = float("inf")
    for i in range(n-k+1):
        ans = min(ans,h[i+k-1]-h[i])
    print(ans)

#D
def D():
    n,x = LI()
    l = [1 for i in range(n+1)]
    for i in range(n):
        l[i+1] = 2*l[i]+3
    p = [1 for i in range(n+1)]
    for i in range(n):
        p[i+1] = 2*p[i]+1
    ans = 0
    for i in range(1,n+1)[::-1]:
        if i == 1:
            if x == 5:ans += 3
            else:ans += max(0,x-1)
        else:
            if x == 0:continue
            if x == l[i]:
                ans += p[i]
                x = 0
            if x > l[i-1]+1:
                ans += p[i-1]+1
                x -= l[i-1]+2
            else:
                x -= 1
    print(ans)
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,x = LI()
    l = [4*2**i-3 for i in range(n+1)]
    s = [2*2**i-1 for i in range(n+1)]
    ans = 0
    while x:
        if x == l[n]:
            ans += s[n]
            break
        if x <= l[n-1]+1:
            n -= 1
            x -= 1
        elif x < l[n]:
            ans += 1+s[n-1]
            x -= 2+l[n-1]
            n -= 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()
# Original solution
n,x = list(map(int,input().split()))
cnt = 0
while n > 0 or x > 0:
    if x >= 2**(n+1)-1:
        cnt += 2**n
        x -= (2**(n+1)-1)
    else:
        x -= 1
    n -= 1
if x >= 1:
    cnt += 1
print(cnt)

# Optimized solution
n,x = list(map(int,input().split()))
cnt = 0
while n > 0 and x > 0:
    if x >= 2**(n+1)-1:
        cnt += 2**n
        x -= (2**(n+1)-1)
    else:
        x -= 1
    n -= 1
if x >= 1:
    cnt += 1
print(cnt)
# Original solution
from functools import lru_cache

@lru_cache()
def f(n):
    if n==0:
        return 1
    return 2*f(n-1)+1

@lru_cache()
def g(n):
    if n==0:
        return 1
    return 2*g(n-1)+3

N, X = list(map(int, input().split()))
total = [g(i) for i in range(N+1)]
p = [f(i) for i in range(N+1)]
ans = 0

def search(x, n):
    global ans
    if n==0:
        if x:
            ans += 1
        return
    if x==0:
        return
    if x > total[n-1] + 2:
        ans += p[n-1] + 1
        search(x-(2 + total[n-1]), n-1)
    elif x == total[n-1] + 2:
        ans += p[n-1] + 1
    else:
        search(x-1, n-1)

search(X, N)
print(ans)

# Optimized solution
N, X = list(map(int, input().split()))
q = [1]*(N+1)
p = [1]*(N+1)
for i in range(1, N+1):
    q[i] = 2*q[i-1]+3
    p[i] = 2*p[i-1]+1

ans = 0
def search(x, n):
    global ans
    if n==0:
        if x:
            ans += 1
        return
    if x==0:
        return
    
    a = q[n-1] + 2
    b = p[n-1] + 1

    if x > a:
        ans += b
        search(x-a, n-1)
    elif x == a:
        ans += b
    else:
        search(x-1, n-1)

search(X, N)
print(ans)
# Original solution
N, X = [int(_) for _ in input().split()]


def calc(n, x, cache = {}):
    #print("calc", n, x)
    key = (n, x)
    if key in cache:
        return cache[key]
    if n == 1:
        if x < 2:
            result = 0
        elif x < 5:
            result = x - 1
        else:
            result = 3
    else:
        plen = 2 * 2 ** n - 3
        if x == 1:
            result = 0
        elif x < 2 + plen:
            result = calc(n - 1, x - 1)
        elif x == 2 + plen:
            result = calc(n - 1, x - 1) + 1
        else:
            result = calc(n - 1, plen) + 1 + calc(n - 1, x - 2 - plen)
    #print("calc", n, x, "=", result)
    cache[key] = result
    return result

result = calc(N, X)

print(result)


# Optimized solution
N, X = [int(_) for _ in input().split()]

def calc(n, x, cache = {}):
    if n == 1:
        return min(max(x - 1, 0), 3)
    else:
        plen = 2 * 2 ** n - 3
        if x == 1:
            return 0
        elif x >= 4 * 2 ** n - 3:
            return 2 * 2 ** n - 1
        elif x < 2 + plen:
            return calc(n - 1, x - 1)
        elif x == 2 + plen:
            return calc(n - 1, x - 1) + 1
        else:
            return 2 ** n + calc(n - 1, x - 2 - plen)

result = calc(N, X)

print(result)
# Original solution
N,X = list(map(int,input().split()))

# 層の総数
T = [1]
for i in range(1, 50+1):
    T.append(T[i-1]*2+3)

def hash(n,x):
    return "{0:d},{1:d}".format(n,x)

# レベルnバーガーの下からx層内のパティの数
memo = dict()
def solve(n,x):
    global T, memo
    if hash(n,x) in memo:
        return memo[hash(n,x)]
    if n == 0 and x >= 1:
        memo[hash(n,x)] = 1
        return 1
    if x <= 1:
        memo[hash(n,x)] = 0
        return 0
    memo[hash(n,x)] = solve(n-1, min(x-1, T[n-1]))
    if x >= T[n-1]+2:
        memo[hash(n,x)] += 1
    if x >= T[n-1]+3:
        memo[hash(n,x)] += solve(n-1, min(x-1-T[n-1]-1, T[n-1]))
    return memo[hash(n,x)]

print((solve(N,X)))


# Optimized solution
N, X = list(map(int, input().split()))
c = [1] * (N + 1)
p = [1] * (N + 1)
for i in range(1, N + 1):
    c[i] = c[i - 1] * 2 + 3
    p[i] = p[i - 1] * 2 + 1
def solve(l, x):
    if l == 0:
        return x
    res = 0
    x -= 1
    if x <= 0: return res
    if x < c[l - 1]:
        res += solve(l - 1, x)
    else:
        res += p[l - 1]
        x -= c[l - 1]
        if x >= 1:
            res += 1
            x -= 1
        if x <= 0: return res
        if x < c[l - 1]:
            res += solve(l - 1, x)
        else:
            res += p[l - 1]
    return res
print((solve(N, X)))
# Original solution
import sys
from functools import lru_cache

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, X = list(map(int, readline().split()))

    @lru_cache(maxsize=None)
    def rec1(i):
        if i == 0:
            return 1
        else:
            return 2 * rec1(i - 1) + 1

    @lru_cache(maxsize=None)
    def rec2(i):
        if i == 0:
            return 1
        else:
            return 2 * rec2(i - 1) + 3

    def rec(i, x):
        if x <= 0:
            return 0
        if i == 0:
            return 1

        x -= 1
        ans = 0
        if x > rec2(i - 1):
            x -= rec2(i - 1)
            ans += rec1(i - 1)
        else:
            ans += rec(i - 1, x)
            return ans

        if x > 0:
            x -= 1
            ans += 1
        else:
            return ans

        if x > rec2(i - 1):
            x -= rec2(i - 1)
            ans += rec1(i - 1)
        else:
            ans += rec(i - 1, x)

        return ans

    print((rec(N, X)))
    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys
from functools import lru_cache

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, X = list(map(int, readline().split()))

    A = [0] * (N + 1)
    B = [0] * (N + 1)
    A[0] = B[0] = 1
    for i in range(N):
        A[i + 1] = 2 * A[i] + 3
        B[i + 1] = 2 * B[i] + 1

    def rec(i, x):
        if i == 0:
            return 1 if x > 0 else 0
        elif x <= 1 + A[i - 1]:
            return rec(i - 1, x - 1)
        else:
            return B[i - 1] + 1 + rec(i - 1, x - 2 - A[i - 1])

    print((rec(N, X)))
    return


if __name__ == '__main__':
    main()
# Original solution
from bisect import bisect
N = int(eval(input()))
B = []
BW = []; BB = []
MB = {}; MW = {}
for i in range(2*N):
    c, a = input().split()
    a = int(a)
    c = "BW".index(c)
    B.append((c, a))
    if c:
        MW[a-1] = i
    else:
        MB[a-1] = i

P = [[0]*(N+1) for i in range(N+1)]
Q = [[0]*(N+1) for i in range(N+1)]

for p in range(N):
    cnt = MW[p] - sum(MW[p0] < MW[p] for p0 in range(p))

    P[p][0] = cnt
    for q in range(N):
        if MB[q] < MW[p]:
            cnt -= 1
        P[p][q+1] = cnt

for q in range(N):
    cnt = MB[q] - sum(MB[q0] < MB[q] for q0 in range(q))

    Q[q][0] = cnt
    for p in range(N):
        if MW[p] < MB[q]:
            cnt -= 1
        Q[q][p+1] = cnt

from heapq import heappush, heappop
dist = [[10**9]*(N+1) for i in range(N+1)]
dist[0][0] = 0
que = [(0, 0, 0)]
while que:
    cost, i, j = heappop(que)
    if dist[i][j] < cost:
        continue
    if i == j == N:
        print(cost)
        break
    if i < N and cost + P[i][j] < dist[i+1][j]:
        dist[i+1][j] = d = cost + P[i][j]
        heappush(que, (d, i+1, j))
    if j < N and cost + Q[j][i] < dist[i][j+1]:
        dist[i][j+1] = d = cost + Q[j][i]
        heappush(que, (d, i, j+1))


# Optimized solution
from bisect import bisect
N = int(eval(input()))
B = []
BW = []; BB = []
MB = {}; MW = {}
for i in range(2*N):
    c, a = input().split()
    a = int(a)
    c = "BW".index(c)
    B.append((c, a))
    if c:
        MW[a-1] = i
    else:
        MB[a-1] = i

P = [[0]*(N+1) for i in range(N+1)]
Q = [[0]*(N+1) for i in range(N+1)]

for p in range(N):
    cnt = MW[p] - sum(MW[p0] < MW[p] for p0 in range(p))

    P[p][0] = cnt
    for q in range(N):
        if MB[q] < MW[p]:
            cnt -= 1
        P[p][q+1] = cnt

for q in range(N):
    cnt = MB[q] - sum(MB[q0] < MB[q] for q0 in range(q))

    Q[q][0] = cnt
    for p in range(N):
        if MW[p] < MB[q]:
            cnt -= 1
        Q[q][p+1] = cnt

dist = [[10**9]*(N+1) for i in range(N+1)]
dist[0][0] = 0
que = [(0, 0, 0)]
for i in range(N):
    dist[i+1][0] = dist[i][0] + P[i][0]
for i in range(N):
    dist[0][i+1] = dist[0][i] + Q[i][0]
for i in range(N):
    for j in range(N):
        dist[i+1][j+1] = min(dist[i][j+1] + P[i][j+1], dist[i+1][j] + Q[j][i+1])
print((dist[N][N]))
# Original solution
import sys
N = int(eval(input()))

ans = []
if N % 2:
    print((N*(N-1)//2 - N//2))
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if i + j != N:
                ans.append("%d %d\n" % (i, j))
else:
    print((N*(N-1)//2 - N//2))
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if i + j != N+1:
                ans.append("%d %d\n" % (i, j))
sys.stdout.writelines(ans)

# Optimized solution
import sys
N = int(sys.stdin.readline())

ans = ["%d\n" % (N*(N-1)//2 - N//2)]
K = N+((N&1)^1)
for i in range(1, N+1):
    for j in range(i+1, N+1):
        if i + j != K:
            ans.append("%d %d\n" % (i, j))
sys.stdout.writelines(ans)
# Original solution
def bfs(graph, start, goal, connection):
    visited = {start: None}
    unvisited = [start]
    while unvisited:
        now = unvisited[0]
        if now == goal or (1000000*now + goal) in connection:
            connection[1000000*start + goal] = 1
            return "yes"
        unvisited = unvisited[1:]
        for next in graph[now][1:]:
            if not (next in visited):
                unvisited.append(next)
                visited[next] = now
    return "no"

n, m = list(map(int, input().split()))
g = [[i] for i in range(n)]
c = {}

for i in range(m):
    inp = list(map(int, input().split()))
    g[inp[0]].append(inp[1])
    g[inp[1]].append(inp[0])

q = int(eval(input()))

for i in range(q):
    s, t = list(map(int, input().split()))
    print((bfs(g, s, t, c)))

# Optimized solution
def bfs(graph, start, goal, connection):
    visited = {start: None}
    unvisited = [start]
    while unvisited:
        now = unvisited[0]
        if now == goal or (1000000*now + goal) in connection:
            connection[1000000*start + goal] = 1
            return "yes"
        unvisited = unvisited[1:]
        for next in graph[now]:
            if not (next in visited):
                unvisited.append(next)
                visited[next] = now
    return "no"

n, m = list(map(int, input().split()))
g = [[] for i in range(n)]
c = {}

for i in range(m):
    inp = list(map(int, input().split()))
    g[inp[0]].append(inp[1])
    g[inp[1]].append(inp[0])

q = int(eval(input()))

for i in range(q):
    s, t = list(map(int, input().split()))
    print((bfs(g, s, t, c)))
# Original solution
n, m = list(map(int, input().split()))

adj = [[] for i in range(n)]

for i in range(m):
    s, t = list(map(int, input().split()))
    adj[s].append(t)
    adj[t].append(s)

isVisited = [False] * n

CC = [None] * n


def dfs(u, group):
    path = []
    path.append(u)
    isVisited[u] = True
    CC[u] = group
    while path:
        u = path[-1]
        if adj[u]:
            v = adj[u].pop(0)
            if not isVisited[v]:
                isVisited[v] = True
                CC[v] = group
                path.append(v)
        else:
            path.pop()

def makeCC(group):
    for i in range(n):
        if not isVisited[i]:
            dfs(i, group)
            group += 1

def isConnected(v1, v2):
    if CC[v1] == CC[v2]:
        print('yes')
    else:
        print('no')


makeCC(0)


q = int(eval(input()))

for i in range(q):
    s, t = list(map(int, input().split()))
    isConnected(s, t)

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

adj = [[] for i in range(n)]

for i in range(m):
    s, t = list(map(int, input().split()))
    adj[s].append(t)
    adj[t].append(s)

groups = [None] * n


def dfs(u, group_num):
    path = []
    path.append(u)
    groups[u] = group_num
    while path:
        u = path[-1]
        if adj[u]:
            v = adj[u].pop(0)
            if not groups[v]:
                groups[v] = group_num
                path.append(v)
        else:
            path.pop()


g_n = 1
for i in range(n):
    if not groups[i]:
        dfs(i, g_n)
        g_n += 1

def isConnected(v1, v2):
    if groups[v1] == groups[v2]:
        print('yes')
    else:
        print('no')


q = int(eval(input()))

for i in range(q):
    s, t = list(map(int, input().split()))
    isConnected(s, t)
# Original solution
from collections import deque
from enum import Enum, auto
import sys
sys.setrecursionlimit(100000)

class Color(Enum):
    WHITE = auto()
    GRAY = auto()
    BLACK = auto()

n, m = list(map(int, input().split(' ')))
adj_list = [[] for i in range(n)]
for i in range(m):
    u, v = list(map(int, input().split(' ')))
    adj_list[u].append(v)
    adj_list[v].append(u)

# 幅優先
def adj_bfs(s, e):
    queue = deque([])
    colors = [Color.WHITE for i in range(n)]

    queue.append(s)
    colors[s] = Color.GRAY

    while len(queue) > 0:
        u = queue.popleft()
        for v in adj_list[u]:
            if colors[v] == Color.WHITE:
                colors[v] = Color.GRAY
                queue.append(v)
                if v == e: return True
        colors[u] = Color.BLACK
    return False

# 深さ優先
colors = [Color.WHITE for i in range(n)]

def adj_dfs(u, e):
    colors[u] = Color.GRAY

    for v in adj_list[u]:
        if colors[v] == Color.WHITE:
            if v == e: return True
            if adj_dfs(v, e):
                return True

    colors[u] = Color.BLACK
    return False

q = int(eval(input()))
for i in range(q):
    s, e = list(map(int, input().split(' ')))
    colors = [Color.WHITE for i in range(n)]
    if adj_dfs(s, e):
        print('yes')
    else:
        print('no')



# Optimized solution
from collections import deque
import sys
sys.setrecursionlimit(100000)

n, m = list(map(int, input().split(' ')))
adj_list = [[] for i in range(n)]
for i in range(m):
    u, v = list(map(int, input().split(' ')))
    adj_list[u].append(v)
    adj_list[v].append(u)

# 深さ優先
# 全ての点をたどって連結しているもの同士を同じ色に設定する
colors = []

def adj_dfs(r, c):
    global colors
    stack = deque([])
    stack.append(r)
    colors[r] = c
    while len(stack) != 0:
        u = stack.pop()
        for v in adj_list[u]:
            if colors[v] == None:
                colors[v] = c
                stack.append(v)

def assign_color():
    global colors
    id = 1
    colors = [None for i in range(n)]
    for u in range(n):
        if colors[u] == None:
            id += 1
            adj_dfs(u, id)

assign_color()

q = int(eval(input()))
for i in range(q):
    s, e = list(map(int, input().split(' ')))
    if colors[s] == colors[e]:
        print('yes')
    else:
        print('no')
# Original solution
# -*- coding: utf-8 -*-
from collections import deque


if __name__ == '__main__':

    n, m = [int(s) for s in input().split(" ")]
    M = [set() for j in range(n)]
    for _ in range(m):
        u, v = [int(s) for s in input().split(" ")]
        M[u].add(v)
        M[v].add(u)
        
    color = [0] * n
    def dfs(u, c):  # depth-first search
        color[u] = c
        for v in range(n):
            if v in M[u] and color[v] == 0:
                dfs(v, c)
        color[u] = c
    
    c = 1
    for u in range(n):
        if color[u] == 0:
            dfs(u, c)
            c += 1
    
    l = int(eval(input()))
    for _ in range(l):
        p, q = [int(s) for s in input().split(" ")]
        if color[p] == color[q]:
            print("yes")
        else:
            print("no")



# Optimized solution
# -*- coding: utf-8 -*-
from collections import deque
import sys
sys.setrecursionlimit(200000)


if __name__ == '__main__':

    n, m = [int(s) for s in input().split(" ")]
    M = [set() for j in range(n)]
    for _ in range(m):
        u, v = [int(s) for s in input().split(" ")]
        M[u].add(v)
        M[v].add(u)
        
    color = [0] * n
    def dfs(u, c):  # depth-first search
        color[u] = c
        for v in M[u]:
            if color[v] == 0:
                dfs(v, c)
    
    c = 1
    for u in range(n):
        if color[u] == 0:
            dfs(u, c)
            c += 1
    
    l = int(eval(input()))
    for _ in range(l):
        p, q = [int(s) for s in input().split(" ")]
        if color[p] == color[q]:
            print("yes")
        else:
            print("no")