#include <iostream>

using namespace std;

int main()
{
    int redovi,kolone,crno;
    cin>>redovi>>kolone>>crno;
    int tabla[redovi][kolone];
    int koordinate[2][crno];
    for(int i=0;i<2;i++)
    {
        for(int j=0; j<crno; j++)
        {
            cin>>koordinate[i][j];
            }
        }
    if(crno+1==redovi*kolone) cout<<1;
    else if(crno+2==redovi*kolone) cout<<2;
    else cout<<3;
    return 0;
}