#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

void get(ll i, ll arr[], ll n, ll xo, ll o, ll &ans)
{
    if(i == n)
    {
        ans = min(ans, xo^o);
        return;
    }
    
    get(i+1, arr, n, xo, o|arr[i], ans);
    get(i+1, arr, n, xo^o, arr[i], ans);
}

const ld PI = acos(-1);

int main()
{
  FAST/**/
  
  ll n;
  cin>>n;
  
  pii arr[n];
  rep(n)
        cin>>arr[i].ff>>arr[i].ss;
  vector<ll> hold[n+1];
  rep(n)
        hold[arr[i].ss].pb(arr[i].ff);
  rep(n+1)
        sort(hold[i].begin(), hold[i].end());
  hold[0].pb(0);
  map<ll,ll> ma[n+1];
  ma[0][0] = 0;
  map<ll, ll> prev = ma[0];
  for(ll i=1;i<=n;i++)
  {
      if(hold[i].size() == 0)
            continue;
      ll x1 = hold[i][0], y1 = hold[i].back();
      ma[i][x1] = ma[i][y1] = inf;
      autoit(prev, it)
      {
          //cout<<"for "<<i<<" , "<<it->ff<<" = "<<it->ss<<'\n';
          ll curr = it->ff, cd = it->ss;
          ma[i][x1] = min(ma[i][x1], cd + abs(curr-y1) + abs(y1-x1));
          ma[i][y1] = min(ma[i][y1], cd + abs(curr-x1) + abs(y1-x1));
      }
      
      prev = ma[i];
  }
  
  ll ans = inf;
  autoit(prev,it)
        ans = min(ans, it->ss + abs(it->ff));
  cout<<ans<<'\n';       
  
  return 0;
}
   
   
 
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>
#include <tuple>
//#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long int;
// 任意長型
//namespace mp = boost::multiprecision;
//using Real = mp::number<mp::cpp_dec_float<128>>;
//using Bint = mp::cpp_int;




int main(int argc, char *argv[])
{
	//input
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;



	//calc
	while (1 <= k){
		string nextS;
		s = s + s;
		if (s.size() % 2){
			s = s + s;
		}

		for (unsigned int i = 0; i < s.size(); i += 2){
			if (s[i] == s[i + 1]){
				nextS.push_back(s[i]);
			}
			else if (s[i] == 'R' && s[i + 1] == 'S'){
				nextS.push_back('R');
			}
			else if (s[i] == 'P' && s[i + 1] == 'R'){
				nextS.push_back('P');
			}
			else if (s[i] == 'S' && s[i + 1] == 'P'){
				nextS.push_back('S');
			}
			else if (s[i] == 'S' && s[i + 1] == 'R'){
				nextS.push_back('R');
			}
			else if (s[i] == 'R' && s[i + 1] == 'P'){
				nextS.push_back('P');
			}
			else if (s[i] == 'P' && s[i + 1] == 'S'){
				nextS.push_back('S');
			}
		}
		s = nextS;

		k--;
	}



	//ans
	cout << s[0] << endl;


	return 0;
}
