#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
namespace do_while_true {
	#define ld double
	#define ll long long
	#define re register
	#define pb push_back
	#define fir first
	#define sec second
	#define pp std::pair<int, int>
	#define mp std::make_pair
	const ll mod = 1000000007;
	template <typename T>
	inline T Max(re T x, re T y) { return x > y ? x : y; }
	template <typename T>
	inline T Min(re T x, re T y) { return x < y ? x : y; }
	template <typename T>
	inline T Abs(re T x) {	return x < 0 ? -x : x; }
	template <typename T>
	inline void read(re T& r) {
		r = 0; bool w = 0; char ch = getchar();
		while(ch < '0' || ch > '9') w = ch == '-' ? 1 : 0, ch = getchar();
		while(ch >= '0' && ch <= '9') r = r * 10 + (ch ^ 48), ch = getchar();
		r = w ? -r : r;
	}
	template <typename T>
	inline T qpow(re T x, re T y) {
		re T sumq = 1; x %= mod;
		while(y) {
			if(y&1) sumq = sumq * x % mod;
			x = x * x % mod;
			y >>= 1;
		}
		return sumq;
	}
}
using namespace do_while_true;

const int N = 10010;

int n, m, k;
int a[N], b[N], c[N][2];
bool vis[N];

void solve() {
	read(n); read(m);
	for(int i = 1; i <= m; ++i) read(a[i]), read(b[i]);
	read(k); int ans = 0;
	for(int i = 1; i <= k; ++i) read(c[i][0]), read(c[i][1]);
	for(int i = 0; i < (1 << k); ++i) {
		for(int j = 1; j <= n; ++j) vis[j] = 0;
		for(int j = 1; j <= k; ++j) {
			int p = (1 << (j-1)) & i;
			p = p>0;
			vis[c[j][p]] = 1;
		}
		int sumq = 0;
		for(int j = 1; j <= m; ++j)
			if(vis[a[j]] && vis[b[j]])
				++sumq;
		ans = Max(ans, sumq);
	}
	printf("%d\n", ans);
}

signed main() {
	#ifndef ONLINE_JUDGE
//	freopen("in.txt", "r", stdin);
	#endif
//	freopen("out1.txt", "w", stdout);
	int T = 1;
//	read(T);
	while(T--)
		solve();
	fclose(stdin);	
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 4e2+5;

char s[N],t[N];

inline char get(char a,char b){
	if(a == b) return a;
	if(a == 'P' && b == 'R') return 'P';
	if(a == 'R' && b == 'P') return 'P';
	if(a == 'S' && b == 'P') return 'S';
	if(a == 'P' && b == 'S') return 'S';
	if(a == 'R' && b == 'S') return 'R';
	if(a == 'S' && b == 'R') return 'R';
}

inline void change(int n){
	for(int i = 0;i < n;++i) t[i] = s[i];
	for(int i = n;i < n*2;++i) t[i] = s[i-n];

	for(int i = 0;i < n;++i)
		s[i] = get(t[i*2],t[i*2+1]);
	return ;
}

int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	scanf("%s",s);
	
	while(k){
		change(n);
		k--;
	}
	printf("%c",s[0]);
	return 0;
}
