#include <bits/stdc++.h>
using namespace std;
const uint64_t seed = std::chrono::system_clock::now().time_since_epoch().count();
mt19937_64 rnd(seed);
const int MOD = 998244353;

#ifdef VIPJML_LOCAL
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << "{";
    for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
    {
        if (vi != v.begin())
            os << ", ";
        os << *vi;
    }
    os << "}";
    return os;
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const vector<pair<A, B>> &v)
{
    os << "{";
    for (typename vector<pair<A, B>>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
    {
        if (vi != v.begin())
            os << ", ";
        os << '(' << vi->first << " " << vi->second << ")";
    }
    os << "}";
    return os;
}

template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
    cerr << ' ' << H;
    dbg_out(T...);
}
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
using LL = long long;

void solve(int caseNum)
{
    LL N, T;
    cin >> N >> T;
    vector<LL> A(N);
    for (int i = 0; i < N; i++)
        cin >> A[i];
    int H1 = N / 2;
    int H2 = N - H1;
    vector<LL> v1(1 << H1, 0);
    vector<LL> v2(1 << H2, 0);
    for (int i = 0; i < H1; i++)
    {
        v1[1 << i] = A[i];
    }
    for (int i = 0; i < H2; i++)
    {
        v2[1 << i] = A[i + H1];
    }
    for (int i = 0; i < (1 << H1); i++)
    {
        int p = (i - 1) & i;
        int q = i - p;
        v1[i] = v1[p] + v1[q];
    }
    sort(v1.begin(), v1.end());
    LL ans = 0;
    for (int i = 0; i < (1 << H2); i++)
    {
        int p = (i - 1) & i;
        int q = i - p;
        v2[i] = v2[p] + v2[q];
        LL r = T - v2[i];
        auto it = upper_bound(v1.begin(), v1.end(), r);
        if (it != v1.begin())
        {
            it--;
            ans = max(ans, v2[i] + *it);
        }
    }
    cout << ans << endl;
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    int T = 1;
    //cin >> T;
    for (int i = 1; i <= T; i++)
    {
        solve(i);
    }
    cout.flush();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;

#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define int long long
#define sz(v) (int)v.size()
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define f(i,l,r) for(long long i=l;i<=r;i++)
#define rf(i,r,l) for(long long i=r;i>=l;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }


const int N = 1e2 + 5, mod = 1e9 + 7, bit = 61;

int dp[N][N], a[N], p[N];
char s[N];
int n, k;
int get(int a, int b)
{
	if (a == 1 or b == 1)
	{
		return max(a, b);
	}
	return min(a, b);
}
map<char, int> mp;

int solve(int x, int pw)
{
	if (pw == 0)
	{
		return a[x];
	}
	int &ans = dp[x][pw];
	if (ans != -1)
	{
		return ans;
	}
	ans = get(solve(x, pw - 1), solve((x + p[pw - 1]) % n, pw - 1));
	return ans;
}

signed main()
{
	fast;


#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	// cin >> t;
	f(tc, 1, t)
	{
		mp['R'] = 0;
		mp['P'] = 1;
		mp['S'] = 2;
		cin >> n >> k;
		p[0] = 1;
		f(i, 1, n)
		{
			p[i] = (p[i - 1] << 1) % n;
		}
		f(i, 0, n - 1)
		{
			cin >> s[i];
			a[i] = mp[s[i]];
		}
		memset(dp, -1, sizeof(dp));
		int res = solve(0, k);
		char ans;
		for (auto &x : mp)
		{
			if (x.ss == res)
			{
				ans = x.ff;
				break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}
