#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
//#define int long long
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PI = pair<pair<int,int>,int>;
using PL = pair<long long, long long>;
using PLL = pair<pair<long long, long long>, long long>;
using Pxy = pair<long double, long double>;
using Tiib = tuple<int, int, bool>;
using vvl = vector<vector<ll>>;
const int INF = 1001001007;
const int modd = 1000000007;
const long long modl = 1000000007LL;
const long long mod = 998244353LL;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

char rps(char a, char b){
    if (a == b) return a;
    if (a == 'P'){
        if (b == 'R') return a;
        else return b;
    }
    if (a == 'R'){
        if (b == 'P') return b;
        else return a;
    }
    if (a == 'S'){
        if (b == 'P') return a;
        else return b;
    }
}

int main(){
    int n, k; cin >> n >> k;
    string s; cin >> s;
    s += s;
    rep(i,k){
        string t = "";
        rep(j,s.size() / 2){
            t += rps(s[2*j],s[2*j+1]);
        }
        t += t;
        s = t;
    }
    cout << s[0] << endl;
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size() 
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)


/****************************** CODE IS HERE ***********************************/


int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int n, m; cin >> n >> m;
    vector <int> A(n), B(m);
    for (int &i: A) cin >> i;
    for (int &i: B) cin >> i;

    vector <vector<int>> dp(n+1, vector<int>(m+1, -1));

    function<int(int, int)> go = [&](int i, int j) {
        if (i == n and j == m) return 0;
        if (i < n and j == m) return (n - i);
        if (i == n and j < m) return (m - j);
        int &res = dp[i][j];
        if (res != -1) return res;
        int ans = 1e9;
        if (A[i] == B[j]) ans = go(i+1, j+1);
        else ans = 1 + go(i+1, j+1);
        ans = min({ans, 1 + go(i+1, j), 1 + go(i, j+1)});
        return res = ans;
    };

    cout << go(0, 0);

    return 0;
}

/*

f(i, j) => min {
        if (A[i] == B[j]) f(i+1, j+1),
        1 + f(i+1, j),
        1 + f(i, j+1),
        1 + f(i+1, j+1)
    }
    
    base cases:
    if (i == n and j == m) return 0;
    if (i < n and j == m) return (n-i);
    if (i == n and j < m) return (m - j);
    
*/

