description: Let's call the string beautiful if it does not contain a substring of length at least 2, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. For example, the strings a, bab, acca, bcabcbacb are palindromes, but the strings ab, abbbaa, cccb are not.
  
  Let's define cost of a string as the minimum number of operations so that the string becomes beautiful, if in one operation it is allowed to change any character of the string to one of the first 3 letters of the Latin alphabet (in lowercase).
  
  You are given a string s of length n, each character of the string is one of the first 3 letters of the Latin alphabet (in lowercase).
  
  You have to answer m queries — calculate the cost of the substring of the string s from l_i-th to r_i-th position, inclusive.
  
  Input
  
  The first line contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the length of the string s and the number of queries.
  
  The second line contains the string s, it consists of n characters, each character one of the first 3 Latin letters.
  
  The following m lines contain two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ n) — parameters of the i-th query.
  
  Output
  
  For each query, print a single integer — the cost of the substring of the string s from l_i-th to r_i-th position, inclusive.
  
  Example
  
  Input
  
  
  5 4
  baacb
  1 3
  1 5
  4 5
  2 3
  
  
  Output
  
  
  1
  2
  0
  1
  
  Note
  
  Consider the queries of the example test.
  
    * in the first query, the substring is baa, which can be changed to bac in one operation; 
    * in the second query, the substring is baacb, which can be changed to cbacb in two operations; 
    * in the third query, the substring is cb, which can be left unchanged; 
    * in the fourth query, the substring is aa, which can be changed to ba in one operation. 
solution: import java.io.OutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.PrintWriter;
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.util.*;
  
  public class Main {
      public static void main(String[] args){
          InputStream inputStream = System.in;
          OutputStream outputStream = System.out;
          InputReader in = new InputReader(inputStream);
          PrintWriter out = new PrintWriter(outputStream);
          solve(in, out);
          out.close();
      }
  
      static String reverse(String s) {
          return (new StringBuilder(s)).reverse().toString();
      }
  
      static void sieveOfEratosthenes(int n, int factors[], ArrayList<Integer> ar) 
      { 
          factors[1]=1;
          int p;
          for(p = 2; p*p <=n; p++) 
          { 
              if(factors[p] == 0) 
              { 
                  ar.add(p);
                  factors[p]=p;
                  for(int i = p*p; i <= n; i += p) 
                      if(factors[i]==0)
                          factors[i] = p; 
              } 
          } 
          for(;p<=n;p++){
              if(factors[p] == 0) 
              { 
                  factors[p] = p;
                  ar.add(p);
              } 
          }
      }
  
      static void sort(int ar[]) {
          int n = ar.length;
          ArrayList<Integer> a = new ArrayList<>();
          for (int i = 0; i < n; i++)
              a.add(ar[i]);
          Collections.sort(a);
          for (int i = 0; i < n; i++)
              ar[i] = a.get(i);
      }
  
      static void sort1(long ar[]) {
          int n = ar.length;
          ArrayList<Long> a = new ArrayList<>();
          for (int i = 0; i < n; i++)
              a.add(ar[i]);
          Collections.sort(a);
          for (int i = 0; i < n; i++)
              ar[i] = a.get(i);
      }
  
      static void sort2(char ar[]) {
          int n = ar.length;
          ArrayList<Character> a = new ArrayList<>();
          for (int i = 0; i < n; i++)
              a.add(ar[i]);
          Collections.sort(a);
          for (int i = 0; i < n; i++)
              ar[i] = a.get(i);
      }
  
      static long ncr(long n, long r, long mod) {
          if (r == 0)
              return 1;
          long val = ncr(n - 1, r - 1, mod);
          val = (n * val) % mod;
          val = (val * modInverse(r, mod)) % mod;
          return val;
      }
  
      static int min[];
      static int gcd[];
      static int freq[];
  
      static void build(int a[], int v, int tl, int tr) {
          if (tl == tr) {
              min[v] = a[tl];
              gcd[v] = a[tl];
              freq[v] = 1;
          } else {
              int tm = (tl + tr) / 2;
              build(a, v*2, tl, tm);
              build(a, v*2+1, tm+1, tr);
              if(min[v*2]<min[v*2+1]){
                  min[v] = min[v*2];
                  freq[v] = freq[v*2];
              }
              else if(min[v*2]>min[v*2+1]){
                  min[v] = min[v*2+1];
                  freq[v] = freq[v*2+1];
              }
              else{
                  min[v] = min[v*2];
                  freq[v] = freq[v*2] + freq[v*2+1];
              }
              gcd[v] = (int)gcd(gcd[v*2], gcd[v*2+1]);
          }
      }
  
      // static void update(int v, int tl, int tr, int x, int new_val) {
      //     t1[v] = Math.max(new_val,t1[v]);
      //     if(tl==tr)
      //         return;
      //     int tm = (tl + tr) / 2;
      //     if(x<=tm)
      //         update(t1, v*2, tl, tm, x, new_val);
      //     else
      //         update(t1, v*2+1, tm+1, tr, x, new_val);
      //     min[v] = Math.min(a[v*2],a[v*2+1]);
      //     gcd[v] = (int)gcd(gcd[v*2], gcd[v*2+1]);
      // }
  
      static Pair get(int v, int tl, int tr, int l, int r) {
          if (tl >= l && tr <= r) {
              return new Pair(min[v], freq[v], gcd[v]);
          }
          int tm = (tl + tr) / 2;
          Pair p1 = new Pair(0,0,0);
          Pair p2 = new Pair(0,0,0);
          int f1 = 0, f2 = 0;
          if(l<=tm){
              p1 = get(v*2, tl, tm, l, r);
              f1 = 1;
          }
          if(r>=tm+1){
              p2 = get(v*2+1, tm+1, tr, l, r);
              f2 = 1;
          }
          if(f1==0)
              return p2;
          if(f2==0)
              return p1;
          if(p1.a<p2.a)
              return new Pair(p1.a, p1.b, (int)gcd(p1.c, p2.c));
          if(p1.a>p2.a)
              return new Pair(p2.a, p2.b, (int)gcd(p1.c, p2.c));
          return new Pair(p1.a, p1.b+p2.b, (int)gcd(p1.c,p2.c));
      }
  
      public static void solve(InputReader sc, PrintWriter pw){
          int i, j = 0;
          int t = 1; 
          long mod = 1000000007;
          // int t = sc.nextInt();
          u: while (t-- > 0) {
              int n = sc.nextInt();
              int m = sc.nextInt();
              char ch[] = sc.next().toCharArray();
              int na[] = new int[n+2];
              int nb[] = new int[n+2];
              int nc[] = new int[n+2];
              char ch1[] = {'a','b','c'};
              for(i=0;i<n;i++){
                  na[i+1] = na[i];
                  nb[i+1] = nb[i];
                  nc[i+1] = nc[i];
                  if(ch[i]==(char)(ch1[i%3])){
                      na[i+1] = na[i]+1;
                  }
                  if(ch[i]==(char)(ch1[(i+1)%3])){
                      nb[i+1] = nb[i]+1;
                  }
                  if(ch[i]==(char)(ch1[(i+2)%3])){
                      nc[i+1] = nc[i]+1;
                  }
                  // pw.println(na[i+1]+" "+nb[i+1]+" "+nc[i+1]);
              }
              na[n+1] = na[n];
              nb[n+1] = nb[n];
              nc[n+1] = nc[n];
              int na1[] = new int[n+2];
              int nb1[] = new int[n+2];
              int nc1[] = new int[n+2];
              char ch2[] = {'c','b','a'};
              for(i=0;i<n;i++){
                  na1[i+1] = na1[i];
                  nb1[i+1] = nb1[i];
                  nc1[i+1] = nc1[i];
                  if(ch[i]==(char)(ch2[i%3])){
                      na1[i+1] = na1[i]+1;
                  }
                  if(ch[i]==(char)(ch2[(i+1)%3])){
                      nb1[i+1] = nb1[i]+1;
                  }
                  if(ch[i]==(char)(ch2[(i+2)%3])){
                      nc1[i+1] = nc1[i]+1;
                  }
                  // pw.println(na1[i+1]+" "+nb1[i+1]+" "+nc1[i+1]);
              }
              na1[n+1] = na1[n];
              nb1[n+1] = nb1[n];
              nc1[n+1] = nc1[n];
              for(i=0;i<m;i++){
                  int l = sc.nextInt();
                  int r = sc.nextInt();
                  int max = Math.max(na[r]-na[l-1],Math.max(nb[r]-nb[l-1],nc[r]-nc[l-1]));
                  max = Math.max(max,Math.max(na1[r]-na1[l-1],Math.max(nb1[r]-nb1[l-1],nc1[r]-nc1[l-1])));
                  pw.println((r-l+1)-max);
              }
          }
      }
  
      static void KMPSearch(char pat[], char txt[], int pres[])
      {
          int M = pat.length;
          int N = txt.length;
          int lps[] = new int[M];
          int j = 0; 
          computeLPSArray(pat, M, lps);
          int i = 0;
          while (i < N) {
              if (pat[j] == txt[i]) {
                  j++;
                  i++;
              }
              if (j == M) {
                  pres[i-1] = 1;
                  j = lps[j - 1];
              }
              else if (i < N && pat[j] != txt[i]) {
                  if (j != 0)
                      j = lps[j - 1];
                  else
                      i = i + 1;
              }
          }
      }
    
      static void computeLPSArray(char pat[], int M, int lps[])
      {
          int len = 0;
          int i = 1;
          lps[0] = 0; 
          while (i < M) {
              if (pat[i] == pat[len]) {
                  len++;
                  lps[i] = len;
                  i++;
              }
              else 
              {
                  if (len != 0) {
                      len = lps[len - 1];
                  }
                  else
                  {
                      lps[i] = len;
                      i++;
                  }
              }
          }
      }
  
      static long[][] matrixMult(long a[][], long b[][], long mod){
          int n = a.length;
          int m = a[0].length;
          int p = b[0].length;
          long c[][] = new long[n][p];
          for(int i=0;i<n;i++){
              for(int j=0;j<m;j++){
                  for(int k=0;k<p;k++){
                      c[i][k] += a[i][j]*b[j][k];
                      c[i][k] %= mod;
                  }
              }
          }
          return c;
      }
  
      static long[][] exp(long mat[][], long b, long mod){
          if(b==0){
              int n = mat.length;
              long res[][] = new long[n][n];
              for(int i=0;i<n;i++){
                  res[i][i] = 1;
              }
              return res;
          }
          long half[][] = exp(mat, b/2, mod);
          long res[][] = matrixMult(half, half, mod);
          if(b%2==1){
              res = matrixMult(res, mat, mod);
          }
          return res;
      }
  
      static void countPrimeFactors(int num, int a[], HashMap<Integer,Integer> pos){
          for(int i=2;i*i<num;i++){
              if(num%i==0){
                  int y = pos.get(i);
                  while(num%i==0){
                      a[y]++;
                      num/=i;
                  }
              }
          }
          if(num>1){
              int y = pos.get(num);
              a[y]++;
          }
      }
  
      static void assignAnc(ArrayList<Integer> ar[], int depth[], int sz[], int par[][] ,int curr, int parent, int d){
          depth[curr] = d;
          sz[curr] = 1;
          par[curr][0] = parent;
          for(int v:ar[curr]){
              if(parent==v)
                  continue;
              assignAnc(ar, depth, sz, par, v, curr, d+1);
              sz[curr] += sz[v];
          }
      }
  
      static int findLCA(int a, int b, int par[][], int depth[]){
          if(depth[a]>depth[b]){
              a = a^b;
              b = a^b;
              a = a^b;
          }
          int diff = depth[b] - depth[a];
          for(int i=19;i>=0;i--){
              if((diff&(1<<i))>0){
                  b = par[b][i];
              }
          }
          if(a==b)
              return a;
          for(int i=19;i>=0;i--){
              if(par[b][i]!=par[a][i]){
                  b = par[b][i];
                  a = par[a][i];
              }
          }
          return par[a][0];
      }
  
      static void formArrayForBinaryLifting(int n, int par[][]){
          for(int j=1;j<20;j++){
              for(int i=0;i<n;i++){
                  if(par[i][j-1]==-1)
                      continue;
                  par[i][j] = par[par[i][j-1]][j-1];
              }
          }
      }
  
      static long lcm(int a, int b){
          return a*b/gcd(a,b);
      }
  
      static class Pair1 {
          long a;
          long b;
          
          Pair1(long a, long b) {
              this.a = a;
              this.b = b;
          }
      }
  
      static class Pair implements Comparable<Pair> {
          int a;
          int b;
          int c;
          
          Pair(int a, int b, int c) {
              this.a = a;
              this.b = b;
              this.c = c;
          }
   
          public int compareTo(Pair p) {
              if(a!=p.a)
                  return a-p.a;
              return b-p.b;
          }
      }
  
      static boolean isPrime(int n) { 
          if (n <= 1) 
              return false; 
          if (n <= 3) 
              return true; 
          if (n % 2 == 0 ||  n % 3 == 0) 
              return false; 
          for (int i = 5; i * i <= n; i = i + 6) 
              if (n % i == 0 || n % (i + 2) == 0) 
                  return false; 
          return true; 
      } 
  
      static long gcd(long a, long b) {
          if (b == 0)
              return a;
          return gcd(b, a % b);
      }
  
      static long fast_pow(long base, long n, long M) {
          if (n == 0)
              return 1;
          if (n == 1)
              return base % M;
          long halfn = fast_pow(base, n / 2, M);
          if (n % 2 == 0)
              return (halfn * halfn) % M;
          else
              return (((halfn * halfn) % M) * base) % M;
      }
  
      static long modInverse(long n, long M) {
          return fast_pow(n, M - 2, M);
      }
  
      static class InputReader {
          public BufferedReader reader;
          public StringTokenizer tokenizer;
  
          public InputReader(InputStream stream) {
              reader = new BufferedReader(new InputStreamReader(stream), 9992768);
              tokenizer = null;
          }
  
          public String next() {
              while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                  try {
                      tokenizer = new StringTokenizer(reader.readLine());
                  } catch (IOException e) {
                      throw new RuntimeException(e);
                  }
              }
              return tokenizer.nextToken();
          }
  
          public int nextInt() {
              return Integer.parseInt(next());
          }
  
          public long nextLong() {
              return Long.parseLong(next());
          }
      }
  }