#include <bits/stdc++.h>
template <class T>
class Bit {
 public:
  T a[262144];
  void add(int x, T k) {
    do a[x] += k, x += x & -x;
    while (x & 262144 - 1);
  }
  T qry(int x) {
    T res = a[0];
    while (x) res += a[x], x -= x & -x;
    return res;
  }
  int lbd(T k) {
    if (!(0 < (k -= a[0]))) return 0;
    int res = 0, x = 262144 >> 1;
    while (x) {
      if (a[res | x] < k) k -= a[res |= x];
      x >>= 1;
    }
    return res + 1;
  }
  int ubd(T k) {
    if (!(0 <= (k -= a[0]))) return 0;
    int res = 0, x = 262144 >> 1;
    while (x) {
      if (a[res | x] <= k) k -= a[res |= x];
      x >>= 1;
    }
    return res + 1;
  }
};
int mp[128];
char s[262144];
int a[262144];
Bit<int> bt[3];
int sum[3];
int count() {
  int fr[3], ba[3];
  for (int i = 0; i < 3; ++i) fr[i] = bt[i].lbd(1);
  for (int i = 0; i < 3; ++i) ba[i] = bt[i].lbd(sum[i]);
  int res = 0;
  for (int i = 0; i < 3; ++i) {
    int f = 262144, b = 0, pr = (i + 2) % 3, nx = (i + 1) % 3;
    for (int j = 0; j < 3; ++j)
      if (j != i) f = std::min(f, fr[j]), b = std::max(b, ba[j]);
    if (sum[nx])
      res += bt[i].qry(f) + sum[i] - bt[i].qry(b) + bt[i].qry(ba[nx]) -
             bt[i].qry(fr[nx]);
    else if (!sum[pr])
      res += sum[i];
  }
  return res;
}
int main() {
  mp['P'] = 0, mp['R'] = 1, mp['S'] = 2;
  int n, q;
  scanf("%d%d", &n, &q);
  scanf("%s", s);
  for (int i = 0; i < n; ++i) a[i] = mp[(int)s[i]];
  for (int i = 0; i < n; ++i) bt[a[i]].add(i, 1), ++sum[a[i]];
  printf("%d\n", count());
  for (int i = 0; i < q; ++i) {
    int k;
    char c;
    scanf("%d %c", &k, &c), --k;
    bt[a[k]].add(k, -1), --sum[a[k]];
    a[k] = mp[(int)c];
    bt[a[k]].add(k, 1), ++sum[a[k]];
    printf("%d\n", count());
  }
  return 0;
}
