import java.util.Scanner;
public class UVa11235{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int[] pos = new int[100001];
int[] num = new int[100000];
int n = input.nextInt();
int q=0;
while(n!=0){
q = input.nextInt();
pos[0]=1;
int before=input.nextInt();
int temp=0;
int count=1;
int z=0;
for(int i=2;i<=n;i++){
temp = input.nextInt();
if(temp!=before)
pos[++z]=i;
before = temp;
}
pos[z+1] = n+1;
int a=0, b=0, first=0, last=0, max=0;
for(int i=0;i<q;i++){
first=0;
last=0;
max=0;
a=input.nextInt();
b=input.nextInt();
while(a>=pos[first]){
first++;
}
last=first-1;
while(b>=pos[last]){
last++;
}
last--;
max=pos[first]-a;
for(int x=first;x<last;x++){
if(pos[x+1]-pos[x]>max)
max = pos[x+1]-pos[x];
}
if(b-pos[last]+1>max)
max = b-pos[last]+1;
if(b<pos[first])
max = b-a+1;
System.out.println(max);
}
n = input.nextInt();
}
}
}