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

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

#define mp make_pair
#define fr first
#define sc second

void solve() {
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    int cnt = count(S.begin(), S.end(), '0');
    if (cnt != count(T.begin(), T.end(), '0')) {
        cout << -1 << '\n';
        return;
    }
    vector<int> p1, p2;
    for (int i = 0; i < N; i++) {
        if (S[i] == '0') {
            p1.push_back(i);
        }
        if (T[i] == '0') {
            p2.push_back(i);
        }
    }
    int ans = 1e6;
    for (int ite = 0; ite < 2; ite++) {
        int reg = 0;
        for (int i = cnt - 1; i >= 0; i--) {
            reg += (p1[i] != p2[i]);
        }
        ans = min(ans, reg);
        reverse(p1.begin(), p1.end());
        reverse(p2.begin(), p2.end());
    }
    cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}

#include <iostream>
#include <cstdio>
#define maxn 105
using namespace std;
int n, k;
int f[maxn][maxn];//2^i以j开始 
char s[maxn];
int cf[maxn];
int match(int x, int y)
{
	if(x < y) swap(x, y);
	if(x == 2 && y == 0) return y;
	else return x;
}
int main()
{
	scanf("%d%d%s", &n, &k, s);
	cf[0] = 1;
	for (int i = 1; i < maxn; i++)
	{
		cf[i] = cf[i - 1] * 2 % n;
	}
	for (int i = 0; i < n; i++)
	{
		if(s[i] == 'R') f[0][i] = 0;
		if(s[i] == 'P') f[0][i] = 1;
		if(s[i] == 'S') f[0][i] = 2;
	}
	for (int i = 1; i <= k; i++)
	{
		for (int j = 0; j < n; j++)
		{
			int x = f[i - 1][j];
			int y = f[i - 1][(j + cf[i - 1]) % n];
			f[i][j] = match(x, y);
		}
	}
	if(f[k][0] == 0) printf("R");
	if(f[k][0] == 1) printf("P");
	if(f[k][0] == 2) printf("S");
	return 0;
}