program grid_game
  implicit none
  integer              :: h, w, n
  integer, allocatable :: x(:), y(:)
  integer              :: i, j, k, l, act, width
  read(*,*) h, w, n
  allocate(x(n),y(n))
  do k = 1, n
     read(*,*) x(k), y(k)
  end do
  call merge_sort(n,y,x)
  call merge_sort(n,x,y)
  act = h
  width = 1
  k = 1
  do i = 1, h
     do while (x(k) .lt. i+1 .and. k .le. n)
        k = k + 1
     end do
     if (x(k) .gt. i+1) then
        width = width + 1
        cycle
     end if
     l = k
     do while (x(k) .eq. i+1 .and. k .le. n .and. y(k) .le. width)
        k = k + 1
     end do
     if (l .ne. k) then
        act = i
        exit
     end if
     if (y(k) .ne. width+1) width = width + 1
  end do
  deallocate(x,y)
  write(*,'(i0)') act
  stop
contains
  subroutine merge_sort(n,x,y)
    implicit none
    integer, intent(in)    :: n
    integer, intent(inout) :: x(n), y(n)
    integer                :: number, length, i, ubound
    number = n
    length = 1
    do while (number .gt. 1)
       do i = 1, number/2
          ubound = min(2*i*length,n)
          call merge(x(2*(i-1)*length+1:(2*i-1)*length),x((2*i-1)*length+1:ubound), &
               & y(2*(i-1)*length+1:(2*i-1)*length),y((2*i-1)*length+1:ubound))
       end do
       length = 2*length
       number = (number+1)/2
    end do
    return
  end subroutine merge_sort

  subroutine merge(x1,x2,y1,y2)
    implicit none
    integer, intent(inout) :: x1(:), x2(:), y1(:), y2(:)
    integer                :: x(size(x1)+size(x2)), y(size(y1)+size(y2))
    integer                :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(x1)
    n2 = size(x2)
    do while (i1 .le. n1 .and. i2 .le. n2)
       if (x1(i1) .le. x2(i2)) then
          x(i1+i2-1) = x1(i1)
          y(i1+i2-1) = y1(i1)
          i1 = i1+1
       else
          x(i1+i2-1) = x2(i2)
          y(i1+i2-1) = y2(i2)
          i2 = i2+1
       end if
    end do
    if (i1 .le. n1) then
       x(i1+i2-1:n1+n2) = x1(i1:n1)
       y(i1+i2-1:n1+n2) = y1(i1:n1)
    else if (i2 .le. n2) then
       x(i1+i2-1:n1+n2) = x2(i2:n2)
       y(i1+i2-1:n1+n2) = y2(i2:n2)
    end if
    x1 = x(1:n1)
    x2 = x(n1+1:n1+n2)
    y1 = y(1:n1)
    y2 = y(n1+1:n1+n2)
    return
  end subroutine merge
end program grid_game