#include <bits/stdc++.h>
using namespace std;
set<long long> s[3];
long long n, q;
string ss;
map<char, long long> mp;
vector<long long> v[3];
const long long inf = 1e16;
class BIT {
 public:
  vector<long long> tree;
  BIT() { tree.resize(400005, 0LL); }
  void upd(long long x, long long v) {
    for (; x <= n; x += (x & (-x))) tree[x] += v;
  }
  long long qry(long long x) {
    long long ret = 0;
    for (; x > 0; x -= (x & (-x))) ret += tree[x];
    return ret;
  }
};
BIT ft[3];
long long getMin(long long id) {
  if (s[id].empty()) return inf;
  return *s[id].begin();
}
long long getMax(long long id) {
  if (s[id].empty()) return -inf;
  auto it = s[id].end();
  it--;
  return *it;
}
long long getsum(long long id, long long l, long long r) {
  return (ft[id].qry(r) - ft[id].qry(l - 1));
}
bool inRange(long long x) { return (x <= n && x >= 1); }
long long GET(long long id) {
  long long cur = v[id][0];
  long long loser = v[id][1];
  long long master = v[id][2];
  long long L = getMin(loser);
  long long R = getMax(loser);
  long long ret = 0;
  if (inRange(L) && inRange(R)) {
    ret += getsum(cur, L, R);
    long long lm = getMin(master);
    long long rm = getMax(master);
    if (!inRange(lm) || !inRange(rm)) return ft[cur].qry(n);
    if (lm > L) {
      ret += getsum(cur, 1, L);
    } else {
      ret += getsum(cur, 1, lm);
    }
    if (rm < R) {
      ret += getsum(cur, R, n);
    } else {
      ret += getsum(cur, rm, n);
    }
    return ret;
  } else {
    if (ft[cur].qry(n) == n) return n;
    return 0;
  }
}
long long prefs[200005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> q;
  mp['R'] = 0;
  mp['P'] = 1;
  mp['S'] = 2;
  v[0] = {0, 2, 1};
  v[1] = {1, 0, 2};
  v[2] = {2, 1, 0};
  cin >> ss;
  for (long long i = 1; i <= n; i++) {
    long long ka = mp[ss[i - 1]];
    prefs[i] = ka;
    ft[ka].upd(i, 1);
    s[ka].insert(i);
  }
  long long ans = 0;
  for (long long i = 0; i < 3; i++) {
    long long y = GET(i);
    ans += y;
  }
  cout << ans << "\n";
  while (q--) {
    long long pos;
    char x;
    cin >> pos >> x;
    long long ka = mp[x];
    s[prefs[pos]].erase(pos);
    ft[prefs[pos]].upd(pos, -1);
    prefs[pos] = ka;
    s[ka].insert(pos);
    ft[ka].upd(pos, 1);
    ans = 0;
    for (long long i = 0; i < 3; i++) {
      long long y = GET(i);
      ans += y;
    }
    cout << ans << "\n";
  }
  return 0;
}
