n,m,k = map(int,input().split())
l = []
ar = [[0]*(m+5) for i in range(n+5)]
flag = 1
ind = -1
for loop in range(k):
x,y = map(int,input().split())
ar[x][y] = 2
if( (flag == 1) and ((ar[x-1][y-1]==2 and ar[x][y-1]==2 and ar[x-1][y]==2) or (ar[x-1][y+1]==2 and ar[x-1][y]==2 and ar[x][y+1]==2) or (ar[x][y-1]==2 and ar[x+1][y-1]==2 and ar[x+1][y]==2) or (ar[x+1][y]==2 and ar[x+1][y+1]==2 and ar[x][y+1]==2))):
ind = loop
flag = 0
if(flag):
print(0)
else:
print(ind+1)
/*
Problem: 508A
Date: 15-11-2023 05:39 PM
*/
#include <bits/stdc++.h>
#define in std::cin
#define out std::cout
#define endl std::endl
#define Max(a, b) ((b) > (a) ? (b) : (a))
#define Max3(a, b, c) Max(a, Max(b, c))
#define Min(a, b) ((b) < (a) ? (b) : (a))
#define Min3(a, b, c) Min(a, Min(b, c))
#define MaxE(a, b) a = Max(a, b)
#define MinE(a, b) a = Min(a, b)
#define Getbit(a, n) ((a >> n) & 1)
#define Bitcount(a) __builtin_popcount(a)
#define S std::string
#define Ss std::stringstream
#define VI std::vector<int>
#define VS std::vector<std::string>
#define VPII std::vector<std::pair<int, int> >
#define VPSI std::vector<std::pair<std::string, int> >
#define VPIS std::vector<std::pair<int, std:;string> >
#define VPSS std::vector<std::pair<std::string, std::string> >
#define Mp(a, b) std::make_pair(a, b)
#define PII std::pair<int, int>
#define PSI std::pair<std::string, int>
#define PIS std::pair<int, std::string>
#define PSS std::pair<std::string, std::string>
#define SI std::set<int>
#define SS std::set<std::string>
#define SPII std::set<std::pair<int, int> >
#define SPSI std::set<std::pair<std::string, int> >
#define SPIS std::set<std::pair<int, std::string> >
#define SPSS std::set<std::pair<std::string, std::string> >
#define VII std::vector<int>::iterator
#define VSI std::vector<std::string>::iterator
#define VPIII std::vector<std::pair<int, int> >::iterator
#define VPISI std::vector<std::pair<int, std::string> >::iterator
#define VPSII std::vector<std::pair<std::string, int> >::iterator
#define VPSSI std::vector<std::pair<std::string, std::string> >::iterator
#define MsI std::multiset<int>
#define MsS std::multiset<std::string>
#define MsPII std::multiset<std::pair<int, int> >
#define MsPSI std::multiset<std::pair<std::string, int> >
#define MsPIS std::multiset<std::pair<int, std::string> >
#define MsPSS std::multiset<std::pair<std::string, std::string> >
#define SII std::set<int>::iterator
#define SPIII std::set<std::pair<int, int> >::iterator
#define SPSII std::set<std::pair<std::string, int> >::iterator
#define SPISI std::set<std::pair<int, std::string> >::iterator
#define SPSSI std::set<std::pair<std::string, std::string> >::iterator
#define MsII std::multiset<int>::iterator
#define MsSI std::multiset<std::string>::iterator
#define MsPIII std::multiset<std::pair<int, int> >::iterator
#define MsPSII std::multiset<std::pair<std::string, int> >::iterator
#define MsPISI std::multiset<std::pair<int, std::string> >::iterator
#define MsPSSI std::multiset<std::pair<std::string, std::string> >::iterator
#define MapII std::map<int, int>
#define MapSS std::map<std::string, std::string>
#define MapIS std::map<int, std::string>
#define MapSI std::map<std::string, int>
#define MapIII std::map<int, int>::iterator
#define MapSSI std::map<std::string, std::string>::iterator
#define MapISI std::map<int, std::string>::iterator
#define MapSII std::map<std::string, int>::iterator
int n, m, k, x, y;
bool a[1000][1000];
int main() {
in >> n >> m >> k;
for(int i = 0; i < k; i++) {
in >> x >> y;
a[--x][--y] = 1;
if((x > 0 && y > 0 && a[x - 1][y - 1] && a[x][y - 1] && a[x - 1][y]) ||
(x > 0 && y < m - 1 && a[x - 1][y + 1] && a[x - 1][y] && a[x][y + 1]) ||
(x < n - 1 && y > 0 && a[x + 1][y - 1] && a[x + 1][y] && a[x][y - 1]) ||
(x < n - 1 && y < m - 1 && a[x + 1][y + 1] && a[x + 1][y] && a[x][y + 1])) {
out << i + 1;
return 0;
}
}
out << 0;
}
1108B - Divisors of Two Integers | 1175A - From Hero to Zero |
1141A - Game 23 | 1401B - Ternary Sequence |
598A - Tricky Sum | 519A - A and B and Chess |
725B - Food on the Plane | 154B - Colliders |
127B - Canvas Frames | 107B - Basketball Team |
245A - System Administrator | 698A - Vacations |
1216B - Shooting | 368B - Sereja and Suffixes |
1665C - Tree Infection | 1665D - GCD Guess |
29A - Spit Problem | 1097B - Petr and a Combination Lock |
92A - Chips | 1665B - Array Cloning Technique |
1665A - GCD vs LCM | 118D - Caesar's Legions |
1598A - Computer Game | 1605A - AM Deviation |
1461A - String Generation | 1585B - Array Eversion |
1661C - Water the Trees | 1459A - Red-Blue Shuffle |
1661B - Getting Zero | 1661A - Array Balancing |