#include <iostream>
using namespace std;
int main()
{
    int n , m , k , xx , yy , x , y;
    bool bx,by;
    bx = true;
    by = true;
    cin >> n >> m >> k;
    cin >> xx >> yy;
    for(int i = 1;i<k;i++)
    {
        cin >> x >> y;
        if(xx != x) bx = false;
        if(yy != y) by = false;
    }
    if(n==2 || m==2)
    {
        if(k==1) n==1;
    }
    else
    {
        if(bx || by) n=1;
    }
    cout << n << endl;
}