h,w,n = gets.split.map(&:to_i)
ans = 10**6
a = Array.new(w+1).map{[]}
b = Hash.new{|h,k|h[k] = Hash.new(false)}
xy = n.times.map{gets.split.map(&:to_i)}.sort
n.times do |i|
    x,y = xy[i]
    b[x][y] = true
    next if y >= x
    a[y] << x
end

for i in 1..w
    a[i].push(h+1)
    b[h+1][i] = true
end

x = y = 1
s = 0
i = 0
loop do
    if i%2 == 0
        if b[x+1][y]
            ans = s+1 if ans > s+1
            break
        else
            x += 1
        end
    else
        m = a[y].bsearch{|j|j > x}
        ans = s+m-x+1 if ans > s+m-x+1
        y += 1 if !b[x][y+1]
        #p !b[x][y+1]
        s += 1
    end
    #p([x,y,ans])
    i += 1
end
puts ans
#p b