CodeEff/ECCO huggingface dataset:
# Original solution
n = int(eval(input()))
a = input().split()
b = []
for i in range(n):
    b.append(a[i])
    b.reverse()

print((" ".join(b)))

# Optimized solution
n = int(eval(input()))
a = input().split()

a_odd = a[0::2]
a_even = a[1::2]

if n % 2 == 1:
    print((" ".join(a_odd[::-1] + a_even)))
else:
    print((" ".join(a_even[::-1] + a_odd)))
# Original solution
N = int(eval(input()))
ARR = [int(s) for s in input().split(" ")]
def calculate(n,arr):

    left = list([])
    right = list([])
    if n % 2 == 0:
        for index,ar in enumerate(arr):
            if index % 2 == 0:
                right.append(str(ar))
            else:
                left.insert(0,str(ar))
    else:
        for index,ar in enumerate(arr):
            if index % 2 == 0:
                left.insert(0,str(ar))
            else:
                right.append(str(ar))
    left.extend(right)

    return left

result = calculate(N,ARR)
print((" ".join(result)))

# Optimized solution
N = int(eval(input()))
ARR = [int(s) for s in input().split(" ")]
def calculate(n,arr):

    left = list([])
    right = list([])
    if n % 2 == 0:
        for index,ar in enumerate(arr):
            if index % 2 == 0:
                right.append(str(ar))
            else:
                left.append(str(ar))
    else:
        for index,ar in enumerate(arr):
            if index % 2 == 0:
                left.append(str(ar))
            else:
                right.append(str(ar))

    left.reverse()
    left.extend(right)

    return left

result = calculate(N,ARR)
print((" ".join(result)))
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))

s = []

for i in range(n):
	s.append(a[i])
	s.reverse()
s = list(map(str,s))
print((' '.join(s)))


# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
q = a[-1]

s = []

for i in range(n):
	s.append(0)

if n%2==1:
	for i in range(n//2+1):
		s[i]=a[-1-2*i]
	for i in range(n//2):
		s[n//2+1+i]=a[2*i+1]
else:
	for i in range(n//2):
		s[i]=a[-1-2*i]
	for i in range(n//2):
		s[n//2+i]=a[2*i]
s = list(map(str,s))
print((" ".join(s)))
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))

ans=[]
[ans.append(a[i]) if i%2 ==0 else ans.insert(0,a[i]) for i in range(n)]
print((str(ans).replace("[","").replace("]","").replace(",","") if n%2 ==0 else str(ans[::-1]).replace("[","").replace("]","").replace(",","") ))

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

ans=[0]*n
for i in range(n):
  if i%2 ==0:
    ans[n//2+i//2]=a[i]
  else:
    ans[n//2-i//2-1]=a[i]

print((str(ans).replace("[","").replace("]","").replace(",","") if n%2 ==0 else str(ans[::-1]).replace("[","").replace("]","").replace(",","") ))
# Original solution
from collections import deque


def main():
    n, *a = open(0).read().split()
    dq = deque()
    n = int(n) - 1
    for i, ai in enumerate(a):
        if i % 2 == n % 2:
            dq.appendleft(ai)
        else:
            dq.append(ai)
    print((" ".join(dq)))
    return


main()


# Optimized solution
def main():
    n, *a = open(0).read().split()
    if int(n) % 2:
        print(" ".join(reversed(a[0::2])), end=" ")
        print(" ".join(a[1::2]))
    else:
        print(" ".join(reversed(a[1::2])), end=" ")
        print(" ".join(a[0::2]))
    return


main()
# Original solution
n = int(eval(input()))
l = list(map(int, input().split()))

even, odd = [], []

for i in range(n):
  if i % 2 == 0:
    even.append(l[i])
  else:
    odd.append(l[i])

if n % 2 == 0:
  ans = odd[::-1] + even
else:
  ans = even[::-1] + odd
ans = list(map(str, ans))
print((' '.join(ans)))

# Optimized solution
n = int(eval(input()))
l = list(map(int, input().split()))
a = []
b = []
for i in range(n):
  if i % 2 == 0:
    a.append(l[i])
  else:
    b.append(l[i])

if n % 2 == 0:
  ans = b[::-1] + a
  print((' '.join(map(str, ans))))
else:
  ans = a[::-1] + b
  print((' '.join(map(str, ans))))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
b=[]

for i in range(n):
    b.append(a[i])
    b.reverse()
s = ""
for b_ in b:
    s+=str(b_)
    s+=" "
s=s.rstrip()
print(s)


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
b1=[]
b2=[]
for i in range(int((n+1)/2)):
    i*=2
    b1.append(a[i])
    i+=1
    if i!=n:
        b2.append(a[i])

s = ""

if n%2==1:
    b3=b2
    b2=b1
    b1=b3
b2.reverse()

for b_ in b2:
    s+=str(b_)
    s+=" "
for b_ in b1:
    s+=str(b_)
    s+=" "
s=s.rstrip()
print(s)
# Original solution
n = int(eval(input()))
a = list(input().split())

b = []
for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.insert(0, a[i])

if n % 2 == 1:
    b = list(reversed(b))

print((' '.join(b)))

# Optimized solution
n = int(eval(input()))
a = list(input().split())

b = ['' for _ in range(n)]
m = n // 2

b[m] = a[0]

p = 1

for i in range(1, n):
    if i % 2 == 1:
        b[m - p] = a[i]
    else:
        b[m + p] = a[i]
        p += 1

if n % 2 == 1:
    b = list(reversed(b))

print((' '.join(b)))
# Original solution
n = int(eval(input()))
a = input().split(' ')
b = []
for i in range(n):
    b.append(a[i])
    b = b[::-1]
print((' '.join(b)))

# Optimized solution
n = int(input())
a = input().split(' ')
b = []
inds = [0] * n

for i in range(int(n/2)):
    inds[i] = n-2*i
    inds[n-1-i] = n-2*i-1
if n % 2 == 1:
    inds[int(n/2)] = n-2*int(n/2)

for i, ind in enumerate(inds):
    print(a[ind-1], end="")
    if i != n-1:
        print(' ', end="")
print('')
# Original solution
n = int(eval(input()))
a = list(map(str, input().split()))
b = []
for i in a:
    b.append(i)
    b = list(reversed(b))
print((" ".join(b)))

# Optimized solution
n = int(eval(input()))
a = list(map(str, input().split()))
b = []
if n%2 == 0:
    print((" ".join(a[1::2][::-1]+a[0::2])))
else:
    print((" ".join(a[0::2][::-1]+a[1::2])))
# Original solution
import sys
from collections import deque

sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(eval(input()))
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

B = deque([])

# print(A, B)

for a in A:
	B.append(a)
	B = deque(reversed(B))
	# print(B)

print((' '.join(map(str, B))))

# Optimized solution
import sys
from collections import deque

sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(eval(input()))
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

B = deque([])

# print(A, B)

for i in range(N):
	if i%2:
		B.append(A[i])
	else:
		B.appendleft(A[i])
	# print(B)

if not N % 2: B = reversed(B)
print((' '.join(map(str, B))))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

b = []

for i in range(n):
    b.append(a[i])
    b.reverse()

b = list(map(str, b))
print((' '.join(b)))

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

a_even = a[0::2]
a_odd  = a[1::2] 

# even
if (n - 1) % 2 == 0: # 0-(n-1)の実施なので(n-1)の偶奇を判定
    b = a_even.copy()
    b.reverse()
    b = b + a_odd
# odd
else:
    b = a_odd.copy()
    b.reverse()
    b = b + a_even

b = list(map(str, b))
print((' '.join(b)))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
ans = []
if n % 2 == 0:
    for i in range(n):
        if i % 2 == 0:
            ans.append(a[i])
        else:
            ans.insert(0, a[i])
else:
    for i in range(n):
        if i % 2 != 0:
            ans.append(a[i])
        else:
            ans.insert(0, a[i])
print((" ".join(map(str, ans))))

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
ev = a[1::2]
od = a[::2]
if n % 2 == 0:
    ev = ev[::-1]
    ans = ev + od
else:
    od = od[::-1]
    ans = od + ev
print((" ".join(map(str, ans))))
# Original solution
iN = int(eval(input()))
aA = [int(_) for _ in input().split()]


if iN == 1:
    print((aA[0]))
elif iN % 2 == 0:
    print((" " .join([str(_) for _ in list(reversed(aA[1::2])) + aA[0::2] ])))
else:
    print((" " .join([str(_) for _ in list(reversed(aA[0::2])) + aA[1::2] ])))


# Optimized solution
iN = int(eval(input()))
aA = [int(_) for _ in input().split()]


if iN == 1:
    print((aA[0]))
else:
    print((" " .join([str(_) for _ in aA[-1::-2] + aA[iN%2::2] ])))
# Original solution
iN = int(eval(input()))
aA = [int(_) for _ in input().split()]


if iN == 1:
    print((aA[0]))
else:
    print((" " .join([str(_) for _ in aA[-1::-2] + aA[iN%2::2] ])))



# Optimized solution
iN = int(eval(input()))
aA = input().rstrip().split()


if iN == 1:
    print((aA[0]))
else:
    print((" " .join(aA[-1::-2] + aA[iN%2::2])))
# Original solution
N = int(eval(input()))
a = list(map(int,input().split()))
b = []
for i in range(N):
  b.append(a[i])
  b.reverse()
print((' '.join(map(str,b))))

# Optimized solution
N = int(eval(input()))
a = list(map(int,input().split()))
b = [0]*N
if N % 2 == 0:
  for i in range(N):
    if (i+1) %2 == 1:
      b[N//2+(i+1)//2] = a[i]
    else:
      b[N//2-(i+1)//2] = a[i]
else:
  for i in range(N):
    if (i+1) %2 == 1:
      b[(N-1)//2-(i+1)//2] = a[i]
    else:
      b[(N-1)//2+(i+1)//2] = a[i]
print((' '.join(map(str,b))))
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
b = []
for i in range(n):
    if i%2 == 0:
        b.append(a[i])
    else:
        b.insert(0,a[i])
if n%2 == 0:
    print((" ".join(list(map(str,b)))))
else:
    c = []
    for i in range(n-1,-1,-1):
        c.append(b[i])
    print((" ".join(list(map(str,c)))))


# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
9753102468
na = n-1
if na%2 == 0:
    nl = na-1
    nr = na
else:
    nl = na
    nr = na-1

b = []
for i in range(nl,0,-2):
    b.append(i)
for i in range(0,nr+1,2):
    b.append(i)

ans = [0 for i in range(n)]
for i,k in enumerate(b):
    if n%2 == 0:
        ans[i] = a[k]
    else:
        ans[n-1-i] = a[k]
print((" ".join(list(map(str,ans)))))
# Original solution
# coding: utf-8
def get_ln_inputs():
    return input().split()


def get_ln_int_inputs():
    return list(map(int, get_ln_inputs()))


def main():
    n = get_ln_int_inputs()[0]
    a = get_ln_int_inputs()
    reverse = n % 2 == 0

    result = list()
    for i in range(n):
        ii = len(result) if i % 2 == 1 else 0
        result.insert(ii, a[i])
    
    if reverse:
        result = result[::-1]

    print((" ".join(str(x) for x in result)))


main()

# Optimized solution
# coding: utf-8
def get_ln_inputs():
    return input().split()


def get_ln_int_inputs():
    return list(map(int, get_ln_inputs()))


def main():
    n = get_ln_int_inputs()[0]
    a = get_ln_int_inputs()

    ilist = []

    t = n
    while t > 0:
        ilist.append(t)
        t -= 2
    if t == -1:
        t = 2
    else:
        t = 1
    while t < n:
        ilist.append(t)
        t += 2
    
    print((" ".join(str(a[i - 1]) for i in ilist)))


main()
# Original solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(eval(input()))
def LS(): return input().split()
def S(): return eval(input())

def main():
  n=I()
  l=LS()

  s=l[0]
  if n%2==0:
    for i in range(1,len(l)):
      if i%2==0:
        s=s+' '+l[i]
      else:
        s=l[i]+' '+s
  else:
    for i in range(1,len(l)):
      if i%2==1:
        s=s+' '+l[i]
      else:
        s=l[i]+' '+s

  return s

print((main()))


# Optimized solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(eval(input()))
def LS(): return input().split()
def S(): return eval(input())

def main():
  n=I()
  l=LS()

  l1=[]
  l2=[]

  for i in range(len(l)):
    if i%2==0:
      l1.append(l[i])
    else:
      l2.append(l[i])

  if n%2==0:
    l2.reverse()
    l2+=l1
    return ' '.join(str(x) for x in l2)
  else:
    l1.reverse()
    l1+=l2
    return ' '.join(str(x) for x in l1)

print((main()))
# Original solution
n = int(eval(input()))
a = input().split()
b = []
for i in range(n):
  if n%2 == 0:
    if i%2== 1:
      b.insert(0,a[i])
    else:
      b.append(a[i])
  else:
    if i%2== 0:
      b.insert(0,a[i])
    else:
      b.append(a[i])
result= ' '.join(b)
print(result)

# Optimized solution
n = int(eval(input()))
num = list(map(str,input().split()))
a,b = [],[]
result = ''
for i in range(n):
  if i%2 == 0:
    a.append(num[i])
  else:
    b.append(num[i])
if n%2 ==1:
  result = ' '.join(a[::-1])
  result += ' ' + ' '.join(b)
else:
  result = ' '.join(b[::-1])
  result += ' ' + ' '.join(a)
print(result)
# Original solution
n = int(eval(input()))
A = input().split()
B = []
for a in A:
    B.append(a)
    B.reverse()
print((' '.join(B)))

# Optimized solution
n = int(eval(input()))
a = input().split()

if n % 2 != 0:
    r, l = a[1::2], a[::2]
else:
    r, l = a[::2], a[1::2]

l.reverse()
print((' '.join(l + r)))
# Original solution
n=int(eval(input()))
a=list(map(int, input().split()))
b=[]
for i in range(n):
    b.append(str(a[i]))
    b=b[::-1]
print((' '.join(b)))

# Optimized solution
n=int(eval(input()))
a=list(map(int, input().split()))
b=[0 for _ in range(n)]
if n%2!=0:
    for i in range(n):
        if i%2==0:
            b[n//2-i//2]=str(a[i])
        else:
            b[n//2+i//2+1]=str(a[i])
else:
    for i in range(n):
        if i%2==0:
            b[n//2+i//2]=str(a[i])
        else:
            b[n//2-i//2-1]=str(a[i])
print((' '.join(b)))
# Original solution
n = int(eval(input()))
a = list(map(str, input().split()))
b = []

for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b = [a[i]] + b

if n % 2 == 1:
    b.reverse()

print((' '.join(map(str, b))))

# Optimized solution
n = int(eval(input()))
a = input().split()

print((' '.join(a[-1::-2] + a[(n % 2)::2])))
# Original solution
n = int(eval(input()))
a = list(input().split())
ans = a[0]
for i in range(n):
	if i%2 == 0 and i != 0:
		ans = ans + ' ' + a[i]
	elif i%2 != 0:
		ans = a[i] + ' ' + ans
if n%2 != 0 and n != 1:
	print((ans[::-1]))
else:
	print(ans)

# Optimized solution
n = int(eval(input()))
a = list(input().split())
a1 = ['']*(n//2 + n%2)
a2 = ['']*(n//2)

for i in range(n):
	if i%2 == 0:
		a1[i//2] = a[i]
	else:
		a2[-i//2] = a[i]

if n%2 != 0 and n != 1:
	ans = ' '.join(a1[::-1]) + ' ' + ' '.join(a2[::-1])
elif n%2 == 0:
	ans = ' '.join(a2) + ' ' + ' '.join(a1)
else:
	ans = a[0]
print(ans)
# Original solution
def C_pushpush(x):
    from collections import deque
    # insertをリストの先頭に行うと、リストの要素の再配置に時間がかかる
    n = int(x[0])
    a = deque(x[1:])
    b = deque([])
    n_parity = n & 1
    for i in range(n):
        if n_parity == (i + 1) & 1:
            # n,iのパリティが一致
            b.appendleft(a[i])
        else:
            b.append(a[i])
    print((' '.join(b)))

n = eval(input())
l = [i for i in input().split()]
x = [n]+l
C_pushpush(x)

# Optimized solution
def c_pushpush(N,A):
    from collections import deque
    # insertをリストの先頭に行うと、リストの要素の再配置に時間がかかる
    b = deque([])
    n_parity = N & 1
    for i in range(N):
        if n_parity == (i + 1) & 1:
            # n,iのパリティが一致
            b.appendleft(A[i])
        else:
            b.append(A[i])
    ans = ' '.join(map(str,b))
    return ans

N = int(eval(input()))
A = [int(i) for i in input().split()]
print((c_pushpush(N,A)))
# Original solution
def c_pushpush(N, A):
    from collections import deque
    ans = deque([])  # リストの先頭への挿入はO(要素数)なので
    n_parity = N & 1
    for i, a in enumerate(A, 1):
        if n_parity == i & 1:
            ans.appendleft(a)
        else:
            ans.append(a)
    return ' '.join(map(str, ans))

N = int(eval(input()))
A = [int(i) for i in input().split()]
print((c_pushpush(N, A)))

# Optimized solution
def c_pushpush():
    # Aの奇数番目の要素と偶数番目の要素をそれぞれ一塊にすることは変わらない。
    # ただし、どちらを左右にするかは N の偶奇によって変わる
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    return ' '.join(map(str, A[int(N % 2 == 0)::2][::-1] + A[int(not N % 2 == 0)::2]))

print((c_pushpush()))
# Original solution
n=int(input())
b=[]
k=0
for i in map(int, input().split()):
  if k%2==0:
    b.append(i)
    k+=1
  else:
    b.insert(0,i)
    k+=1
if n%2!=0:
  b=b[::-1]
print(*b,sep=" ")


# Optimized solution
N=int(input())
A=list(map(int,input().split()))
print(*A[::-2],end=" ")
print(*A[N%2::2])
# Original solution
N = int(input())
S = list(map(int, input().split()))
b = []
for i in range(N):
  if (i + N) % 2 == 0:
    b.append(S[i])
  else:
    b = [S[i]] + b[:]
for i in range(N - 1):
  print(b[i], end = ' ')
print(b[N - 1])


# Optimized solution
N = int(input())
S = list(map(int, input().split()))
b = [0 for i in range(N)]
if N % 2 == 0:
  for i in range(N):
    if i % 2 == 0:
      b[(N + i) // 2] = S[i]
    else:
      b[(N - i) // 2] = S[i]
else:
  b[N // 2] = S[0]
  for i in range(1, N):
    if i % 2 == 1:
      b[(N + i) // 2] = S[i]
    else:
      b[(N - i) // 2] = S[i]
for i in range(N - 1):
  print(b[i], end = ' ')
print(b[N - 1])
# Original solution
n, m = list(map(int, input().split()))
ab=[0]*m
for i in range(m):
    ab[i] = [int(x) for x in input().split()]
ab.sort()
ans = 1
key = ab[0][1]
for i in range(m):
    if ab[i][0] >= key:
        ans += 1
        key = ab[i][1]
    elif ab[i][1] < key:
        key = ab[i][1]
print(ans)

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

bridge = [None]*m
for i in range(m):
  a, b = list(map(int, input().split()))
  bridge[i] = [b, a]

ans = 0
bridge.sort()

sub = -1
ans = 0
for v in bridge:
  b, a = v[0], v[1]
  if a >= sub:
    sub = b
    ans += 1

print(ans)
# Original solution
n, m = list(map(int, input().split()))
wars = {}
for i in range(m):
  a, b = list(map(int, input().split()))
  if a in list(wars.keys()):
    wars[a].append(b)
  else:
    wars[a] = [b]

cuts = 0
antis = []

for i in range(1, n):
  if i in list(wars.keys()):
    antis.append(min(wars[i]))
  if i + 1 in antis:
    cuts += 1
    antis.clear()
    
print(cuts)


# Optimized solution
n, m = list(map(int, input().split()))
wars = {}
for i in range(m):
  a, b = list(map(int, input().split()))
  if a in list(wars.keys()):
    wars[a] = min(wars[a], b)
  else:
    wars[a] = b

cuts = 0
antis = 10**6

for i in range(1, n):
  if i in list(wars.keys()):
    antis = min(antis, wars[i])
  if i + 1 == antis:
    cuts += 1
    antis = 10**6
    
print(cuts)
# Original solution
n,m  = list(map(int, input().split()))

ans = 0
ba = [[0 for _ in range(2)] for _ in range(m)]

for i in range(m):
    a,b = list(map(int, input().split()))
    ba[i][0] = b
    ba[i][1] = a

ba.sort()

br = 0
for b,a in ba:
    #if bridge[(a-1):] != 0:
    if not (a < br < b):
        #bridge[b-2] = 0
        br = b - 0.5
        ans += 1

print(ans)

# Optimized solution
N,M = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(M)]
ab.sort()
ans = 1
l, r = ab[0][0], ab[0][1]

for a,b in ab[1:]:
    if a < r:
        l = max(l,a)
        r = min(r,b)
    else:
        ans += 1
        l = a
        r = b 

print(ans)
# Original solution



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

AB = [tuple(map(int, input().split())) for _ in range(M)]
AB.sort()

l,r = 1,N

ans = 1
for a,b in AB:

    if r <= a:
        ans += 1
        l,r = a,b
    else:
        l = max(l,a)
        r = min(r,b)

print(ans)

# Optimized solution

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

ab = []
for i in range(M):
    a,b = list(map(int, input().split()))
    ab.append((a,b))

ab.sort()


ans = 1
l = 1
r = N
for a,b in ab:
    if a < r:
        l = a
        r = min(r,b)
    else:
        ans += 1
        l = a
        r = b
print(ans)
# Original solution
N, M = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(M)]
ab.sort(key = lambda x : x[1])

ans = 0
last = -1
for abTemp in ab:
    if abTemp[0] < last:
        continue
    else:
        ans += 1
        last = abTemp[1]

print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(M)]
ab.sort(key = lambda x : x[1])

ans = 0
last = -1
for a, b in ab:
    if a < last:
        continue
    else:
        ans += 1
        last = b

print(ans)
# Original solution
N, M = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(M)]
ab.sort(key = lambda x : x[1])

ans = 0
last = -1
for a, b in ab:
    if a < last:
        continue
    else:
        ans += 1
        last = b

print(ans)

# Optimized solution
import sys

N, M = list(map(int, input().split()))
ab = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
ab.sort(key = lambda x : x[1])

ans = 0
last = -1
for a, b in ab:
    if a < last:
        continue
    else:
        ans += 1
        last = b

print(ans)
# Original solution
n,m=list(map(int,input().split()))
b=[]
for i in range(m):
    b.append(list(map(int,input().split())))
    b.sort(key=lambda x:x[1])
time=0
count=0
for k in range(len(b)):
    if b[k][0]>=time:
                time=b[k][1]
                count+=1
print(count)

# Optimized solution
n,m=list(map(int,input().split()))
b=[]
for i in range(m):
    b.append(list(map(int,input().split())))
b.sort(key=lambda x:x[1])
time=0
count=0
for k in range(len(b)):
    if b[k][0]>=time:
                time=b[k][1]
                count+=1
print(count)
# Original solution
N, M = list(map(int, input().split()))

AB = []
for _ in range(M):
    a, b = list(map(int, input().split()))
    AB.append((a, b))

import copy
import collections

fights = AB[:]

fights = sorted(fights)

bridges = []
for a,b in fights:
    bridges.append(
        [x for x in range(a,b)]
    )

ans = 0
while True:
    if not bridges:
        break
    else:
        ans += 1
    
    flat_b = []
    for b in bridges:
        flat_b = flat_b + b

    #print(flat_b)
    max_n = collections.Counter(flat_b).most_common()[0][0]
    
    next_bridges = []
    for b in bridges:
        if max_n in b:
            continue
        else:
            next_bridges.append(b[:])
    bridges = copy.deepcopy(next_bridges)

print(ans)

# Optimized solution
N, M = list(map(int, input().split()))

AB = []
for _ in range(M):
    a, b = list(map(int, input().split()))
    AB.append((a, b))

fights = AB[:]

fights = sorted(fights, reverse=True)

import bisect


bridges = []
for a,b in fights:
    a_position = bisect.bisect(bridges, a)
    b_position = bisect.bisect(bridges, b)
    
    if a_position == b_position:
        bisect.insort(bridges, a+1)
        #print(bridges)

print((len(bridges)))
# Original solution
import heapq

N, M =list(map(int, input().split()))
p = []

for _ in range(M):
    A, B= list(map(int, input().split()))
    n = B - A
    m = {i for i in range(A, B)}
    heapq.heappush(p, (n, m))

n = 0
sets = []
for _ in range(M):
    n, q = heapq.heappop(p)
    for m, s in sets:
        if len(s - q) == 0:
            break
    else:
        heapq.heappush(sets, (max(q), q))
    
count = 0
minnum = -1
for _ in range(len(sets)):
    n, q = heapq.heappop(sets)
    if minnum in q:
        continue
    minnum = n
    count += 1

print(count)

# Optimized solution
import sys
import itertools
input = sys.stdin.readline


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


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def main():
    N, M = read_values()
    Q = [read_list() for _ in range(M)]
    Q.sort()

    res = 0
    end = 10 ** 6
    for q in Q:
        if q[0] >= end:
            res += 1
            end = q[1]
        else:
            end = min(end, q[1])
    
    res += 1
    print(res)


if __name__ == "__main__":
    main()