#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const ll mod=998244353;
const int N=2e6+1;
int n,k;
char c[101];
ll md[101];
char dp[101][101];//
char win(char x,char y){
	if(x==y) return x;
	if(x+y=='P'+'S') return 'S';
	if(x+y=='P'+'R') return 'P';
	return 'R';
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cin >> n >> k;
	md[0]=1;
	for(int i=0; i<n ;i++){
		cin >> c[i];
		dp[0][i]=c[i];
	}
	md[0]=1;
	for(int j=1; j<=k ;j++){
		md[j]=md[j-1]*2%n;
	}
	for(int i=1; i<=k ;i++){
		for(int j=0; j<n ;j++){
			dp[i][j]=win(dp[i-1][j],dp[i-1][(j+md[i-1])%n]);
		}
	}
	cout << dp[k][0] << '\n';
}
#include <bits/stdc++.h>
using namespace std;
//const long nPrime = 1000000007;
//const long nPrime = 998244353;
int main() {
    long n,k;
    cin >> n >> k;
    vector<vector<long>> vviGrid(n,vector<long>(n));
    for(long i = 0; i < n; i++){
        for(long j = 0; j < n; j++){
            cin >> vviGrid[i][j];
        }
    }
  
    long iOK = 2e9, iNG = -1;
    while(iOK - iNG > 1){
        long iTmp = (iOK+iNG)/2;
        vector<vector<long>> vviGridThis(n,vector<long>(n));
        for(long i = 0; i < n; i++){
            for(long j = 0; j < n; j++){
                vviGridThis[i][j] = (iTmp<vviGrid[i][j]) ? 1 : 0;
            }
        }
        vector<vector<long>> vviSum(n+1,vector<long>(n+1,0));
        for(long i = 1; i <= n; i++){
            for(long j = 1; j <= n; j++){
                vviSum[i][j] = vviSum[i-1][j]+vviSum[i][j-1]-vviSum[i-1][j-1]+vviGridThis[i-1][j-1];
            }
        }
        
        long iMin = 1e9;
        for(long i = k; i <= n; i++){
            for(long j = k; j <= n; j++){
                long iThis = vviSum[i][j]-vviSum[i][j-k]-vviSum[i-k][j]+vviSum[i-k][j-k];
                iMin = min(iMin, iThis);
            }
        }
        if(iMin >= (k*k)/2+1){
            iNG = iTmp;
        } else {
            iOK = iTmp;
        }
    }
  
    cout << iOK << endl;
    return 0;
}