#include <iostream>
using namespace std;


int main(int argc, const char * argv[]) {

   long long unsigned int levo=0,desno=0,gore=0,dole=0,boja=2;

    long long int red,kolona,brojCrnihPolja,i;
    cin>> red>>kolona>>brojCrnihPolja;
    long long int Crnapoljay[brojCrnihPolja],Crnapoljax[brojCrnihPolja];
    long long int mca[red][kolona],x,y;
    for (i =0 ; i < brojCrnihPolja;i ++)
        {
            
            cin>>Crnapoljay[i]>>Crnapoljax[i];
            mca[Crnapoljay[i]-1][Crnapoljax[i]-1]= 1;
        }
    for (y=0;y<red;y++)
        {
            for (x=0 ; x<kolona ; x++)
                 {
                     if (mca[y][x]!=1)
                         {
                             mca[y][x]=0;
                             
                         }
                 }
        }
    for (y=0;y<red;y++)
        {
            for (x = 0 ; x < kolona ; x++)
                {
                    if (mca[y][x]==0)
                    {
                        mca[y][x]=boja;

                           for (long long unsigned int i = x;i>-1; i--)
                               {
                                   if (mca[y][i]==1)
                                        {
                                            levo = 1;
                                            break;
                                        }
                                   if (mca[y][i]==0)
                                   {
                                       mca[y][i] = boja;
                                   }

                               }
                          
                           for (long long unsigned int i = x;i<kolona;i++ )
                                {
                                    if(mca[y][i] == 1)
                                    {
                                        desno = 1;
                                        break;
                                        
                                    }
                                    if (mca[y][i] == 0)
                                        {
                                              mca[y][i] = boja;
                                            
                                        }

                                    }
                        for (long long unsigned int i = y;i<red;i++ )
                           {
                               if(mca[i][x] == 1)
                               {
                                   dole = 1;
                                   break;
                                   
                               }
                               if (mca[i][x] == 0)
                                   {
                                         mca[i][x] = boja;
                                       
                                   }

                               }
                           for (long long unsigned int i = y;i>-1;i-- )
                              {
                                  if(mca[i][x] == 1)
                                  {
                                      gore = 1;
                                      break;
                                      
                                  }
                                  if (mca[i][x] == 0)
                                      {
                                            mca[i][x] = boja;
                                          
                                      }

                                  }
                           
                           if (levo==1&&desno==1&&dole==1)
                               {
                                   boja+=1;
                                   continue;
                               }
                           else if (desno==1&&dole==1)
                                  {
                                      boja+=1;
                                      continue;
                                  }
                           else if (levo==1&&dole==1)
                                     {
                                         boja+=1;
                                         continue;
                                     }
                           else
                               {
                                   continue;
                               }
                        
    

                    }
                  
                    if (mca[y][x]>0 && mca[y][x]!=1)
                        {
                            boja = mca[y][x];
                            for (long long unsigned int i = x;i>-1; i--)
                                                          {
                                                              if (mca[y][i]==1)
                                                                   {
                                                                       levo = 1;
                                                                       break;
                                                                   }
                                                              if (mca[y][i]==0)
                                                              {
                                                                  mca[y][i] = boja;
                                                              }

                                                          }
                                                     
                                                      for (long long unsigned int i = x;i<kolona;i++ )
                                                           {
                                                               if(mca[y][i] == 1)
                                                               {
                                                                   desno = 1;
                                                                   break;
                                                                   
                                                               }
                                                               if (mca[y][i] == 0)
                                                                   {
                                                                         mca[y][i] = boja;
                                                                       
                                                                   }

                                                               }
                                                   for (long long unsigned int i = y;i<red;i++ )
                                                      {
                                                          if(mca[i][x] == 1)
                                                          {
                                                              dole = 1;
                                                              break;
                                                              
                                                          }
                                                          if (mca[i][x] == 0)
                                                              {
                                                                    mca[i][x] = boja;
                                                                  
                                                              }

                                                          }
                                                      for (long long unsigned int i = y;i>-1;i-- )
                                                         {
                                                             if(mca[i][x] == 1)
                                                             {
                                                                 gore = 1;
                                                                 break;
                                                                 
                                                             }
                                                             if (mca[i][x] == 0)
                                                                 {
                                                                       mca[i][x] = boja;
                                                                     
                                                                 }

                                                             }
                                                      
                                                      if (levo==1&&desno==1&&dole==1)
                                                          {
                                                              boja+=1;
                                                              continue;
                                                          }
                                                      else if (desno==1&&dole==1)
                                                             {
                                                                 boja+=1;
                                                                 continue;
                                                             }
                                                      else if (levo==1&&dole==1)
                                                                {
                                                                    boja+=1;
                                                                    continue;
                                                                }
                                                      else
                                                          {
                                                              continue;
                                                          }
                                                   
                            
                            
                        }
                    
                }
            
        }
 
                
    cout<<boja-2;
    


 
    
    return 0;
}