from collections import deque
boardSize = int(input())
appleNum = int(input())
# ๋งต ์์ฑ
board = [[0]*boardSize for _ in range(boardSize)]
# ์ฌ๊ณผ ์์น ์ ์ฅ (1๋ก ํ์)
for _ in range(appleNum):
row,col=map(int,input().split())
board[row-1][col-1] = 1
# ๋ช
๋ น ์ ์ฅ (key : value ๋ก)
commands = {}
commandNum = int(input())
for _ in range(commandNum):
sec,command = map(str,input().split())
commands[int(sec)]=command
# direction์ด 0 ์ธ ๊ฒฝ์ฐ ์๋์ชฝ
# 1์ธ ๊ฒฝ์ฐ ์ค๋ฅธ์ชฝ
# 2์ธ ๊ฒฝ์ฐ ์์ชฝ
# 3์ธ ์ผ์ชฝ
dRow = [-1,0,1,0]
dCol = [0,1,0,-1]
# ์ด๊ธฐ ๋ฐฉํฅ 1, ์ด๊ธฐ ์๊ฐ 0, ์ด๊ธฐ ์์น (0,0), ๋ฑ ์์น๋ 2๋ก ํ์
direction = 1
time = 1
row,col = 0,0
snake = deque([])
snake.append([row,col])
board[row][col] = 2
def change_direction(command,direction):
# D๋ ์ค๋ฅธ์ชฝ์ผ๋ก ๋ฐฉํฅ ๋ณ๊ฒฝ
if(command == 'D'):
return (direction+1)%4
elif(command == 'L'):
return (direction-1)%4
## ์งํ
while True:
row = dRow[direction] + row
col = dCol[direction] + col
# ๊ฒ์์ด ๋๋์ง ์๋ ์กฐ๊ฑด
if 0<= row < boardSize and 0<= col < boardSize and board[row][col] != 2:
#์ฌ๊ณผ ์์ผ๋ฉด ๊ผฌ๋ฆฌ ์ ๊ฑฐํ๊ณ 0์ผ๋ก ์ด๊ธฐํ
if board[row][col] != 1:
tailRow,tailCol=snake.popleft()
board[tailRow][tailCol]=0
# ๋ค์ ์์น 2๋ก ๋ฐ๊พธ๊ณ ํ์ ์ถ๊ฐ
board[row][col] = 2
snake.append([row,col])
if time in commands:
direction = change_direction(commands[time],direction)
time+=1
else:
break
print(time)