#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200002;
class fenwickTree {
 public:
  int n;
  vector<int> bit;
  void init(int _n) {
    n = _n;
    bit.resize(n + 1);
  }
  void upd(int id, int val) {
    for (; id <= n; id += id & -id) bit[id] += val;
  }
  int get(int id) {
    int res = 0;
    for (; id > 0; id -= id & -id) {
      res += bit[id];
    }
    return res;
  }
  int get(int u, int v) { return get(v) - get(u - 1); }
};
int n, nQueries;
char a[MAX_N];
priority_queue<int> R[3];
priority_queue<int, vector<int>, greater<int> > L[3];
fenwickTree tr[3];
int getID(char c) {
  if (c == 'R') return 0;
  if (c == 'P') return 1;
  return 2;
}
void readInput() {
  cin >> n >> nQueries;
  for (int i = 0; i < 3; ++i) tr[i].init(n);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    tr[getID(a[i])].upd(i, 1);
    L[getID(a[i])].push(i);
    R[getID(a[i])].push(i);
  }
}
void upd(int pos, char newShape) {
  tr[getID(a[pos])].upd(pos, -1);
  a[pos] = newShape;
  tr[getID(a[pos])].upd(pos, 1);
  L[getID(a[pos])].push(pos);
  R[getID(a[pos])].push(pos);
}
int query() {
  for (int i = 0; i < 3; ++i) {
    if (tr[i].get(1, n) == n) return n;
  }
  for (int i = 0; i < 3; ++i) {
    if (tr[i].get(1, n) == 0) return tr[(i + 2) % 3].get(1, n);
  }
  int res = 0, tmp1 = n + 1, tmp2 = 0;
  for (int i = 0; i < 3; ++i) {
    while (L[i].size() && getID(a[L[i].top()]) != i) L[i].pop();
    while (R[i].size() && getID(a[R[i].top()]) != i) R[i].pop();
    res += tr[(i + 1) % 3].get(L[i].top(), R[i].top());
    if (L[i].top() > 1) tmp1 = min(tmp1, L[i].top() - 1);
    if (R[i].top() < n) tmp2 = max(tmp2, R[i].top() + 1);
  }
  return res + tmp1 + (n - tmp2 + 1);
}
void solve() {
  cout << query() << '\n';
  while (nQueries--) {
    int pos;
    char newShape;
    cin >> pos >> newShape;
    upd(pos, newShape);
    cout << query() << '\n';
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  readInput();
  solve();
}
