#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    int n, m, l, left, right, ans;
    cin >> n >> m;
    string s;
    cin >> s;
    string a[6] = {"abc", "bca", "cab", "acb", "bac", "cba"};
    for (int i = 0; i < 6; i++) {
      for (int j = 3; j < n; j++) {
        a[i].append(1, a[i][j - 3]);
      }
    }
    int b[6][n + 1];
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j <= n; j++) {
        if (j == 0) {
          b[i][j] = 0;
        } else if (s[j - 1] == a[i][j - 1]) {
          b[i][j] = b[i][j - 1];
        } else {
          b[i][j] = b[i][j - 1] + 1;
        }
      }
    }
    while (m--) {
      cin >> left >> right;
      ans = 1000000;
      for (int i = 0; i < 6; i++) {
        ans = min(ans, b[i][right] - b[i][left - 1]);
      }
      cout << ans << endl;
    }
  }
}
