#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<vector<int>> f(6, vector<int>(n));
  int cnt = 0;
  string a = "abc";
  do {
    string t;
    while (((int)t.size()) < n) t += a;
    t.resize(n);
    for (int i = (0), _b = (n - 1); i <= _b; ++i) {
      f[cnt][i] = int(s[i] != t[i]);
      if (i) f[cnt][i] += f[cnt][i - 1];
    }
    ++cnt;
  } while (next_permutation(a.begin(), a.end()));
  while (q--) {
    int l, r, res;
    cin >> l >> r;
    --l, --r;
    res = n;
    for (int i = (0), _b = (cnt - 1); i <= _b; ++i)
      res = min(res, l ? f[i][r] - f[i][l - 1] : f[i][r]);
    cout << res << '\n';
  }
  return 0;
}
