#include <bits/stdc++.h>
using namespace std;
class TreeNode {
 public:
  bool inc;
  bool is4;
  int lower;
  int upper;
  int max4String;
  int max47String;
  int max7String;
  int max74String;
  TreeNode* left;
  TreeNode* right;
  TreeNode(int intoLower, int intoUpper, char* list) {
    lower = intoLower;
    upper = intoUpper;
    inc = true;
    if (lower == upper) {
      if (list[lower] == '4')
        is4 = true;
      else
        is4 = false;
      left = NULL;
      right = NULL;
    } else {
      left = new TreeNode(lower, (lower + upper) / 2, list);
      right = new TreeNode((lower + upper) / 2 + 1, upper, list);
    }
    getMax4String();
    getMax7String();
    getMax47String();
    getMax74String();
  }
  void change(int low, int high) {
    if (lower > high || upper < low) return;
    if (low == lower && high == upper) {
      inc = !inc;
      return;
    }
    left->change(low, high > left->upper ? left->upper : high);
    right->change(low < right->lower ? right->lower : low, high);
    getMax4String();
    getMax7String();
    getMax47String();
    getMax74String();
  }
  void getMax4String() {
    if (lower == upper)
      max4String = (is4 == inc);
    else {
      int leftPart = left->inc ? left->max4String : left->max7String;
      int rightPart = right->inc ? right->max4String : right->max7String;
      max4String = leftPart + rightPart;
    }
  }
  void getMax7String() {
    if (lower == upper)
      max7String = (is4 != inc);
    else {
      int leftPart = left->inc ? left->max7String : left->max4String;
      int rightPart = right->inc ? right->max7String : right->max4String;
      max7String = leftPart + rightPart;
    }
  }
  void getMax47String() {
    if (lower == upper)
      max47String = 1;
    else {
      int leftPart1 = left->inc ? left->max4String : left->max7String;
      int rightPart1 = right->inc ? right->max47String : right->max74String;
      int leftPart2 = left->inc ? left->max47String : left->max74String;
      int rightPart2 = right->inc ? right->max7String : right->max4String;
      max47String = max(leftPart1 + rightPart1, leftPart2 + rightPart2);
    }
  }
  void getMax74String() {
    if (lower == upper)
      max74String = 1;
    else {
      int leftPart1 = left->inc ? left->max7String : left->max4String;
      int rightPart1 = right->inc ? right->max74String : right->max47String;
      int leftPart2 = left->inc ? left->max74String : left->max47String;
      int rightPart2 = right->inc ? right->max4String : right->max7String;
      max74String = max(leftPart1 + rightPart1, leftPart2 + rightPart2);
    }
  }
  int maxSameSmall(int low, int high, bool sum) {
    if (lower > high || upper < low) return 0;
    sum = (sum == inc);
    if (low >= lower && high <= upper)
      return sum ? max4String : max7String;
    else
      return left->maxSameSmall(low, high, sum) +
             right->maxSameSmall(low, high, sum);
  }
  int maxSameLarge(int low, int high, bool sum) {
    if (lower > high || upper < low) return 0;
    sum = (sum == inc);
    if (low >= lower && high <= upper)
      return sum ? max7String : max4String;
    else
      return left->maxSameLarge(low, high, sum) +
             right->maxSameLarge(low, high, sum);
  }
  int maxDiffIncreasing(int low, int high, bool sum) {
    if (lower > high || upper < low) return 0;
    sum = (sum == inc);
    if (low >= lower && high <= upper)
      return sum ? max47String : max74String;
    else
      return max(left->maxSameSmall(low, high, sum) +
                     right->maxDiffIncreasing(low, high, sum),
                 left->maxDiffIncreasing(low, high, sum) +
                     right->maxSameLarge(low, high, sum));
  }
};
int main() {
  int length, queries;
  cin >> length >> queries;
  char* numbers = new char[length + 1];
  cin >> numbers;
  TreeNode* root = new TreeNode(0, length - 1, numbers);
  for (int i = 0; i < queries; i++) {
    char* chars = new char[10];
    cin >> chars;
    int start, end;
    if (chars[0] == 's') {
      cin >> start >> end;
      root->change(start - 1, end - 1);
    } else
      cout << root->maxDiffIncreasing(0, length - 1, true) << endl;
  }
  return 0;
}
