#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
int N, Q;
char state[MAXN + 5];
set<int> rock, paper, scissors;
int bitRock[MAXN + 5], bitScissors[MAXN + 5], bitPaper[MAXN + 5];
void bitAdd(int* BIT, int idx, int val) {
  while (idx <= N) {
    BIT[idx] += val;
    idx += (idx & (-idx));
  }
}
int bitGet(int* BIT, int idx) {
  int ret = 0;
  while (idx > 0) {
    ret += BIT[idx];
    idx -= (idx & (-idx));
  }
  return ret;
}
void deleteIn(int idx) {
  if (state[idx] == 'R') {
    rock.erase(idx);
    bitAdd(bitRock, idx, -1);
  } else if (state[idx] == 'S') {
    scissors.erase(idx);
    bitAdd(bitScissors, idx, -1);
  } else if (state[idx] == 'P') {
    paper.erase(idx);
    bitAdd(bitPaper, idx, -1);
  }
}
void addInWith(int idx, char kar) {
  state[idx] = kar;
  if (state[idx] == 'R') {
    rock.insert(idx);
    bitAdd(bitRock, idx, 1);
  } else if (state[idx] == 'S') {
    scissors.insert(idx);
    bitAdd(bitScissors, idx, 1);
  } else if (state[idx] == 'P') {
    paper.insert(idx);
    bitAdd(bitPaper, idx, 1);
  }
}
int leftPaper() { return *paper.begin(); }
int leftRock() { return *rock.begin(); }
int leftScissors() { return *scissors.begin(); }
int rightPaper() { return *paper.rbegin(); }
int rightRock() { return *rock.rbegin(); }
int rightScissors() { return *scissors.rbegin(); }
int rockIn(int le, int ri) {
  if (le >= ri) {
    return 0;
  }
  return bitGet(bitRock, ri) - bitGet(bitRock, le - 1);
}
int paperIn(int le, int ri) {
  if (le >= ri) {
    return 0;
  }
  return bitGet(bitPaper, ri) - bitGet(bitPaper, le - 1);
}
int scissorsIn(int le, int ri) {
  if (le >= ri) {
    return 0;
  }
  return bitGet(bitScissors, ri) - bitGet(bitScissors, le - 1);
}
int retriveAns() {
  if (rock.size() && scissors.size() && paper.size()) {
    return rock.size() - rockIn(leftPaper(), leftScissors()) -
           rockIn(rightScissors(), rightPaper()) + paper.size() -
           paperIn(leftScissors(), leftRock()) -
           paperIn(rightRock(), rightScissors()) + scissors.size() -
           scissorsIn(leftRock(), leftPaper()) -
           scissorsIn(rightPaper(), rightRock());
  }
  int cnt = (rock.size() > 0) + (scissors.size() > 0) + (paper.size() > 0);
  if (cnt == 1) {
    return rock.size() + scissors.size() + paper.size();
  }
  if (rock.size() && paper.size()) {
    return paper.size();
  }
  if (paper.size() && scissors.size()) {
    return scissors.size();
  }
  if (scissors.size() && rock.size()) {
    return rock.size();
  }
  assert(false);
}
int main(int argc, char** argv, char** envp) {
  scanf("%d %d", &N, &Q);
  scanf("%s", state + 1);
  for (int i = 1; i <= N; i++) {
    if (state[i] == 'R') {
      bitAdd(bitRock, i, 1);
      rock.insert(i);
    } else if (state[i] == 'S') {
      bitAdd(bitScissors, i, 1);
      scissors.insert(i);
    } else if (state[i] == 'P') {
      bitAdd(bitPaper, i, 1);
      paper.insert(i);
    }
  }
  printf("%d\n", retriveAns());
  while (Q--) {
    int idx;
    char kar;
    scanf("%d %c", &idx, &kar);
    deleteIn(idx);
    addInWith(idx, kar);
    printf("%d\n", retriveAns());
  }
}
