import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto N = s[2];
    auto P = new int[][](W);
    foreach (_; 0..N) {
        s = readln.split.map!(to!int);
        P[s[1]-1] ~= s[0]-1;
    }
    foreach (j; 0..W) {
        P[j] ~= H;
        P[j].sort();
    }

    int r = 0;
    int c = 0;
    int t = 0;
    int ans = 1 << 29;

    while (c < W) {
        auto rr = P[c].assumeSorted.upperBound(r).front;
        ans = min(ans, t + rr - r);
        if (rr == r + 1) {
            break;
        }
        r += 1;
        t += 1;
        if (c + 1 < W && P[c+1].assumeSorted.upperBound(r-1).front != r) {
            c += 1;
        }
    }

    ans.writeln;
}
