#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T> ostream &operator<<(ostream &os, multiset<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) { dump_func(__VA_ARGS__) }
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

template<typename T, typename U> 
T modpow(T a, U n, int mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
char versus(const char&a, const char b){
    char res = a;
    if(a == b)res = a;
    else{
        if(a == 'R' && b == 'P')res = 'P';
        if(a == 'P' && b == 'R')res = 'P';
        if(a == 'P' && b == 'S')res = 'S';
        if(a == 'S' && b == 'P')res = 'S';
        if(a == 'S' && b == 'R')res = 'R';
        if(a == 'R' && b == 'S')res = 'R';
    }
    return res;
}
int N, K;
string S;
char dp[200][200];
// lenは2^lenになる
char dfs(int st, int len){
    if(dp[st][len] != 'X'){
        return dp[st][len];
    }
    else{
        return dp[st][len] = versus(dfs(st, len-1), dfs((st + modpow(2, len-1, N))%N, len-1));
    }
}

int main() {
    cin >> N >> K >> S;
    rep(i,200)rep(j,200)dp[i][j] = 'X';
    rep(i,N){
        dp[i][0] = S[i];
    }
    cout << dfs(0, K) << endl;
    rep(i,N)rep(j,K){
        dump(i, j, dp[i][j]);
    }
}

//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

#define PT pair<ll, int>

int N, M, K;
vector<int> E[100001];
int D[100001], C[100];
int DD[20][20];
int dp[20][1 << 17];
int sagasu(int p, int b) {
	if (dp[p][b]) return dp[p][b];
	int ret = 1e9;
	rep(i, K) if(i != p && (b >> i & 1)) {
		chmin(ret, sagasu(i, b ^ (1 << p)) + DD[i][p]);
	}
	return dp[p][b] = ret;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	cin >> N >> M;
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		E[a].pb(b);
		E[b].pb(a);
	}
	cin >> K;
	rep(i, K) cin >> C[i];

	rep(k, K) {

		rep1(i, N) D[i] = 1e9;
		priority_queue<PT, vector<PT>, greater<PT>> que;
		D[C[k]] = 0;
		que.push(mp(0, C[k]));
		while (que.size()) {
			PT p = que.top();
			que.pop();
			int i = p.second;
			if (D[i] != p.first) continue;
			for (int j : E[i]) {
				ll d = D[i] + 1;
				if (D[j] > d) {
					D[j] = d;
					que.push(mp(d, j));
				}
			}
		}
		rep(p, K) {
			DD[k][p] = D[C[p]];
			dp[p][1 << k | 1 << p] = DD[k][p] + 1;
		}
	}



	int kotae = 1e9;
	rep(i, K) chmin(kotae, sagasu(i, (1 << K) - 1));

	if (kotae < 1e8) co(kotae);
	else co(-1);

	Would you please return 0;
}