#pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <tuple>
#include <deque>
using namespace std;
int map[102][102]; // 맵 저장용
int check[102][102]; // 뱀 움직임 연산용
queue<pair<int, char>> moves; // 움직임
int answer = 0;
int dx[] = { 0,1,0,-1 }; // 각각 방향을 상 우 하 좌 를 0, 1, 2, 3으로 매핑
int dy[] = { -1,0,1,0 };
void init(int N)
{ // 맵 테두리 벽 치기
for (int i = 0; i < N; i++)
{
map[0][i] = -1;
map[N - 1][i] = -1;
check[0][i] = -1;
check[N - 1][i] = -1;
}
for (int j = 0; j < N; j++)
{
map[j][0] = -1;
map[j][N - 1] = -1;
check[j][0] = -1;
check[j][N - 1] = -1;
}
}
int turn_right(int cd)
{ // 우회전
if (cd == 0) return 1;
else if (cd == 1) return 2;
else if (cd == 2) return 3;
else return 0;
}
int turn_left(int cd)
{ // 좌회전
if (cd == 0) return 3;
else if (cd == 3) return 2;
else if (cd == 2) return 1;
else return 0;
}
int turn(int cd, char d)
{ // 회전시키기
if (d == 'L')
return turn_left(cd);
else
return turn_right(cd);
}
void snake_move(int x, int y, int d, int N)
{ // 뱀 움직이기
queue<pair<int, int>> snake; // 뱀 몸 좌표 저장용
check[y][x] = 1; // 최초 위치 초기화
snake.push(make_pair(x, y)); // snake에 현재 좌표 넣기
int cd = d; // 현재 방향 초기화
int time = 0;
while (1)
{
time++; // 시간 증가
int cx, cy;
cx = snake.back().first; 현재 위치 초기화
cy = snake.back().second;
int nx, ny;
nx = cx + dx[cd];
ny = cy + dy[cd];
if (check[ny][nx] != 0 || (nx <= 0 && N + 1 <= nx && ny <= 0 && N + 1 <= ny))
{ // 뱀의 머리가 몸에 부딧히거나 벽이면 끝낸다.
answer = time;
return;
}
check[ny][nx] = 1; // 다음 위치가 접근 가능한경우 접근
snake.push(make_pair(nx, ny)); // 다음 위치를 큐에 넣는다.
if (map[ny][nx] == 1)
{//다음에 사과가 있다면
map[ny][nx] = 0; // 사과 먹기
}
else
{//사과가 없다면
int tx, ty;
tx = snake.front().first;
ty = snake.front().second; // 뱀 몸이 위치하는데서 맨 꼬리값을 반환받고
check[ty][tx] = 0; // 꼬리칸 지운다.
snake.pop(); // 지우기
}
if (!moves.empty() && moves.front().first == time)
{//움직여야 할 경우가 남아있고, 움직일(방향전환) 시간이 되었다면
cd = turn(cd, moves.front().second); // 방향을 전환한다.
moves.pop(); // 방향 전환 후 이전 방향값들은 pop.
}
}
}
int main()
{
//
int N, K;
scanf("%d", &N);
scanf("%d", &K);
init(N + 2);
while (K--)
{
int x, y;
scanf("%d %d", &y, &x);
map[y][x] = 1;
}
int L;
scanf("%d", &L);
while (L--)
{
int t;
char d;
cin >> t;
cin >> d;
moves.push(make_pair(t, d));
}
snake_move(1, 1, 1, N);
printf("%d\n", answer);
//system("pause");
return 0;
}