#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    int a, b, n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i < k; i++)
        cin >> a >> b;
    if (k < m && k < n)
        cout << 1 << "\n";
    else
        cout << 3 << "\n";
    return 0;
}