#include <iostream>
using namespace std;
int main()
{
    int n , m , k, j , xx , yy , x , y;
    bool bx,by;
    bx = true;
    by = true;
    bool s = false;
    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) s=true;
    }
    else
    {
        if(bx==true || by==true) j=1;
        else {
        if(k==2) s=true;
        }
    }
    if(s==true)
    {
        j = 1;
    }
    else
    {
        j = 5;
    }
    cout << j << endl;
    return (0);
}