#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;
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979;
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()

ll modpow(ll base, ll pow){
    ll ret = 1;
    while(pow>0){
        if(pow & 1) ret = ret * base % MOD;
        base = base*base % MOD;
        pow >>= 1;
    }
    return ret;
}

int main(){
    ll n, p; cin >> n >> p;
    ll ans = modpow(p-2, n-1);
    ans = ans * (p-1) % MOD;
    cout << ans << endl;
}