#include <cstdio>
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
using namespace std;
/* FOR READING */
const int BUFFER_SIZE = 2000000;
char buffer[BUFFER_SIZE];
#define SKIP_WHITE_SPACES while(isspace(*buffer_pointer)) { ++buffer_pointer; }
#define READ_INTEGER(x) x = 0; while (isdigit(*buffer_pointer)) { x = x * 10 + *buffer_pointer - '0'; ++buffer_pointer; }
/* FOR PROBLEM */
const int MAXN = 100000;
const int MAX_SQRT_N = 317;
const int MAXA = 100000;
int a[MAXN];
int blockMode[MAX_SQRT_N] = {}; /*By default is 0, but fixed in initialize*/
int blockCount[MAXA+1][MAX_SQRT_N] = {};
int histogram[MAXA + 1] = {}; /* will be cleaned just relevant */
int blockSize;
#define GET_BLOCK_INDEX(i) ((i) / blockSize)
#define FIRST_INDEX_IN_BLOCK(i) ((i)*blockSize)
#define LAST_INDEX_IN_BLOCK(i) (FIRST_INDEX_IN_BLOCK((i)+1)-1)
#define COUNT_IN_BLOCKS(left, right, value) (blockCount[(value)][(right)] - blockCount[(value)][(left)-1])
int main()
{
/* READING */
register char *buffer_pointer = buffer;
fread(buffer, 1, BUFFER_SIZE, stdin);
register int n, q;
SKIP_WHITE_SPACES
READ_INTEGER(n)
SKIP_WHITE_SPACES
READ_INTEGER(q)
/* INITIALIZATION */
blockSize = (int)sqrt(1.0L*n);
for (register int i = 0; i < n; ++i)
{
/* READING */
SKIP_WHITE_SPACES
READ_INTEGER(a[i])
/* INITIALIZATION */
int j = GET_BLOCK_INDEX(i);
if (++blockCount[a[i]][j] > blockCount[blockMode[i]][j])
{
blockMode[i] = a[i];
}
}
while (q--)
{
/* READING */
register int left, right;
SKIP_WHITE_SPACES
READ_INTEGER(left)
SKIP_WHITE_SPACES
READ_INTEGER(right)
/* COUNTING */
register int i;
register int modeCount = 0;
if (right - left + 1 <= blockSize)
{
for (i = left; i <= right; ++i)
{
if (++histogram[a[i]] > modeCount)
{
modeCount = histogram[a[i]];
}
}
// cleaning
for (i = left; i <= right; ++i)
{
histogram[a[i]] = 0;
}
}
else
{
const int leftBlock = GET_BLOCK_INDEX(left), rightBlock = GET_BLOCK_INDEX(right);
const int lastInLeftBlockIndex = LAST_INDEX_IN_BLOCK(leftBlock), firstInRightBlockIndex = FIRST_INDEX_IN_BLOCK(rightBlock);
for (i = left; i <= lastInLeftBlockIndex; ++i)
{
int currentCount = ++histogram[a[i]] + COUNT_IN_BLOCKS(leftBlock + 1, rightBlock - 1, a[i]);
if (currentCount > modeCount)
{
modeCount = currentCount;
}
}
for (i = firstInRightBlockIndex; i <= right; ++i)
{
int currentCount = ++histogram[a[i]] + COUNT_IN_BLOCKS(leftBlock + 1, rightBlock - 1, a[i]);
if (currentCount > modeCount)
{
modeCount = currentCount;
}
}
for (i = leftBlock + 1; i <= rightBlock - 1; ++i)
{
int currentCount = histogram[blockMode[i]] + COUNT_IN_BLOCKS(leftBlock + 1, rightBlock - 1, blockMode[i]);
if (currentCount > modeCount)
{
modeCount = currentCount;
}
}
// cleaning
for (i = left; i <= lastInLeftBlockIndex; ++i)
{
histogram[a[i]] = 0;
}
for (i = firstInRightBlockIndex; i <= right; ++i)
{
histogram[a[i]] = 0;
}
}
printf("%d\n", modeCount);
}
return 0;
}