#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> con(m, {0, 0});
    rep(i, m) cin >> con[i][0] >> con[i][1];
    int k;
    cin >> k;
    vector<vector<int>> k_s(k, {0, 0});
    vector<int> choise(k);
    rep(i, k) cin >> k_s[i][0] >> k_s[i][1];
    int re = pow(2, k);
    int ans = 0;
    rep(i, re)
    {
        rep(j, k)
        {
            if ((i >> j) & 1 == 1)
            {
                choise[j] = k_s[j][1];
            }
            else
            {
                choise[j] = k_s[j][0];
            }
        }
        int match = 0;
        vector<vector<int>> count(m, {0, 0});
        rep(j, k)
        {
            rep(l, m)
            {
                if (choise[j] == con[l][0])
                {
                    count[l][0]++;
                }
                if (choise[j] == con[l][1])
                {
                    count[l][1]++;
                }
            }
        }
        rep(j, m)
        {
            if (count[j][0] > 0 && count[j][1] > 0)
            {
                match++;
            }
        }
        ans = max(ans, match);
    }
    cout << ans << endl;
}

#include <algorithm>
#include <iomanip>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <numeric>
#include <vector>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using i64 = long long;
template<class T, class U>
bool chmin(T& a, const U& b) { return (b < a) ? (a = b, true) : false; }
template<class T, class U>
bool chmax(T& a, const U& b) { return (b > a) ? (a = b, true) : false; }

template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;

char winnner(char a, char b)
{
    if(a == b) return a;
    if(a == 'R' && b == 'S')
    {
        return 'R';
    }
    if(a == 'S' && b == 'R')
    {
        return 'R';
    }
    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';
    }
}

int main()
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    s += s;

    rep(j, k)
    {
        string n_s = "";
        for (int i = 0; i < int(s.size()) - 1; i += 2)
        {
            n_s += winnner(s[i], s[i + 1]);
        }
        s = n_s + n_s;
    }

    cout << s[0] << endl;

    return 0;
}