#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 10;
int n, q;
string second;
set<int> pos[3];
int a[MAXN][3];
map<char, int> m;
int get(int id, int p) {
  int res = 0;
  while (p >= 0) {
    res += a[p][id];
    p = (p & (p + 1)) - 1;
  }
  return res;
}
pair<int, int> intr(pair<int, int> x, pair<int, int> y) {
  return {max(x.first, y.first), min(x.second, y.second)};
}
int calc(int id) {
  int good = (id + 1) % 3, bad = (id + 2) % 3;
  vector<pair<int, int> > fi, se;
  if (pos[bad].size() == 0) {
    return pos[id].size();
  }
  fi.push_back({0, *pos[bad].begin() - 1});
  se.push_back({*pos[bad].rbegin() + 1, n - 1});
  if (pos[good].size() > 0) {
    fi.push_back({*pos[good].begin() + 1, n - 1});
    se.push_back({0, *pos[good].rbegin() - 1});
  }
  vector<pair<int, int> > v;
  for (int i = 0; i < fi.size(); i++) {
    for (int j = 0; j < se.size(); j++) {
      pair<int, int> cur = intr(fi[i], se[j]);
      if (cur.first <= cur.second) v.push_back(cur);
    }
  }
  sort(v.begin(), v.end());
  int sum = 0, maxr = -1;
  for (int i = 0; i < v.size(); i++) {
    int from = max(v[i].first, maxr + 1), to = v[i].second;
    if (from <= to) {
      maxr = max(maxr, to);
      sum += get(id, to) - get(id, from - 1);
    }
  }
  return sum;
}
int solve() {
  int res = 0;
  for (int i = 0; i < 3; i++) {
    res += calc(i);
  }
  return res;
}
void upd(int id, int p, int add) {
  while (p < n) {
    a[p][id] += add;
    p |= (p + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q >> second;
  m['R'] = 0;
  m['S'] = 1;
  m['P'] = 2;
  for (int i = 0; i < n; i++) {
    upd(m[second[i]], i, 1);
    pos[m[second[i]]].insert(i);
  }
  cout << solve() << '\n';
  while (q--) {
    int p;
    char c;
    cin >> p >> c;
    p--;
    pos[m[second[p]]].erase(p);
    upd(m[second[p]], p, -1);
    pos[m[c]].insert(p);
    upd(m[c], p, 1);
    second[p] = c;
    cout << solve() << '\n';
  }
  return 0;
}
