#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int a[100100], n, k;
int niz[100100];

int solve(int l, int d) {
    for (int i = l; i <= d; i++) niz[a[i]] = 0;
    int res, poc;
    res = 0;
    poc = l;
    for (int i = l; i <= d; i++) {
        if (niz[a[i]] >= poc) {
            if (res < i - poc) res = i - poc;
            poc = niz[a[i]]+1;
        }
        niz[a[i]] = i;
    }
    if (res < d+1 - poc) res = d+1 - poc;
    //printf("RRR%d", poc);
    return res;
}


int main() {
    FILE *ff = fopen("knjige.in", "r");
    FILE *gg = fopen("knjige.out", "w");
    fscanf(ff, "%d%d", &n, &k);
    //n = 100000;
    //k = 1000;
    for (int i = 1; i <= n; i++) fscanf(ff, "%d", &a[i]);
        //a[i] = i;
    for (int i = 1; i <= k; i++) {
        int ll, dd;
        fscanf(ff, "%d%d", &ll, &dd);
        //l = 1;
        //d = n;
        int res = solve(ll, dd);
        fprintf(gg, "%d\n", res);
    }
}
