output_description: Print the number of actions Takahashi will end up performing.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      H W N
      X_1 Y_1
      :
      X_N Y_N
attempt: import bisect
  import os
  import sys
  
  if os.getenv("LOCAL"):
      sys.stdin = open("_in.txt", "r")
  
  sys.setrecursionlimit(10**9)
  INF = float("inf")
  IINF = 10**18
  MOD = 10**9 + 7
  # MOD = 998244353
  
  
  H, W, N = list(map(int, sys.stdin.buffer.readline().split()))
  XY = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]
  
  blocked = set()
  blocks = [[] for _ in range(W + 1)]
  for h, w in sorted(XY):
      blocked.add((h, w))
      blocks[w].append(h)
  for w in range(W + 1):
      blocks[w].append(H + 1)
  
  # 高橋くんは毎回動く
  # 青木くんが動く回数を決めたとき、先に動けるだけ動くとする
  # 後から動いたほうがいい場合はもっと動く回数を少なくできるので
  h, w = 1, 1
  hist = []
  while True:
      hist.append((h, w))
      if h + 1 <= H and (h + 1, w) not in blocked:
          h += 1
      else:
          break
      if w + 1 <= W and (h, w + 1) not in blocked:
          w += 1
  
  ans = INF
  for h, w in hist:
      hi = bisect.bisect_left(blocks[w], h + 1)
      ans = min(ans, blocks[w][hi] - 1)
      # print(h, w, blocks[w])
  print(ans)
  
problem_description: Statement
  
  Takahashi and Aoki will play a game using a grid with H rows and W columns of
  square cells. There are N obstacles on this grid; the i-th obstacle is at
  (X_i,Y_i). Here, we represent the cell at the i-th row and j-th column (1 \leq
  i \leq H, 1 \leq j \leq W) by (i,j). There is no obstacle at (1,1), and there
  is a piece placed there at (1,1).
  
  Starting from Takahashi, he and Aoki alternately perform one of the following
  actions:
  
    * Move the piece to an adjacent cell. Here, let the position of the piece be (x,y). Then Takahashi can only move the piece to (x+1,y), and Aoki can only move the piece to (x,y+1). If the destination cell does not exist or it is occupied by an obstacle, this action cannot be taken.
    * Do not move the piece, and end his turn without affecting the grid.
  
  The game ends when the piece does not move twice in a row.
  
  Takahashi would like to perform as many actions (including not moving the
  piece) as possible before the game ends, while Aoki would like to perform as
  few actions as possible before the game ends. How many actions will Takahashi
  end up performing?
samples: [{"input": "3 3 1\n    3 2", "output": "2\n    \n\nFor example, the game proceeds as follows:\n\n  * Takahashi moves the piece to (2,1).\n  * Aoki does not move the piece.\n  * Takahashi moves the piece to (3,1).\n  * Aoki does not move the piece.\n  * Takahashi does not move the piece.\n\nTakahashi performs three actions in this case, but if both players play\noptimally, Takahashi will perform only two actions before the game ends.\n\n* * *"}, {"input": "10 10 14\n    4 3\n    2 2\n    7 3\n    9 10\n    7 7\n    8 1\n    10 10\n    5 4\n    3 4\n    2 8\n    6 4\n    4 4\n    5 8\n    9 2", "output": "6\n    \n\n* * *"}, {"input": "100000 100000 0", "output": "100000"}]