if __name__=='__main__':
st, ed = map(int,input().split())
n = int(input())
ra = []
for i in range(n):
a,b = map(int,input().split())
ra.append([a,b])
ra.sort()
res = 0
success = False
i = 0
while i < n:
j = i
r = -float('inf')
while j < n and ra[j][0] <= st:
r = max(r,ra[j][1])
j += 1
if r < st:
break
res += 1
if r >= ed:
success = True
break
st = r
i = j - 1
i += 1
print(res if success else -1)