#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
set<int>pos[30];
int n, q, nxt[N][26];
char s[N];
int main() {
freopen("Time.in", "r", stdin);
freopen("Time.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> q;
cin >> (s + 1);
for (int i = 1; i <= n; i++) {
int c = s[i] - 'a';
pos[c].insert(i);
for (int j = 0; j < 26; j++) {
if (c != j) nxt[i][j] = i;
}
}
for (int j = 0; j < 26; j++) {
for (int i = n; i >= 1; i--) {
if (!nxt[i][j]) nxt[i][j] = nxt[i + 1][j];
}
}
int l, r;
ll x, y, z, ans;
while (q--) {
cin >> l >> r;
ans = -1;
for (int j = 0; j < 26; j++) {
auto it = pos[j].lower_bound(r + 1);
if (it != pos[j].begin()) {
--it;
y = (*it);
int x = nxt[l][j];
if (x && x <= y && y > l) {
int mid = (x + y) >> 1;
it = pos[j].lower_bound(mid);
if (it != pos[j].end()) {
z = (*it);
if (x < z && z < y) {
ans = max(ans, (z - x) * (y - z));
}
}
if (it != pos[j].begin()) {
it--;
z = (*it);
if (x < z && z < y) {
ans = max(ans, (z - x) * (y - z));
}
}
}
}
}
cout << ans << '\n';
}
return 0;
}