import java.util.*;

public class rebobinar {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        long n = s.nextLong(), k = s.nextLong(), q = s.nextLong();

        long[] L = new long[(int)q];
        long[] R = new long[(int)q];
        for (int i = 0; i < q; i++) {
            L[i] = s.nextLong();
            R[i] = s.nextLong();
        }

        // Percorre de trás pra frente
        for (int i = (int)q - 1; i >= 0; i--) {
            if (L[i] <= k && k <= R[i]) {
                k = L[i] + R[i] - k;
            }
        }

        System.out.println(k);
        s.close();
    }
}
