# Original solution
from collections import deque
N,Q=list(map(int, input().split()))

#重複分を引く

class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
        
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    # I: idx(base: 1), x: value
    def add(self, i, x):
        # assert i > 0
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
            
    # i<=x<j
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)


C=list(map(int, input().split()))
state=[-1]*N
que=[]
for i in range(N):
    c=C[i]
    if state[c-1]==-1:
        state[c-1]=i+1
    else:
        que.append((state[c-1],i+1))
        state[c-1]=i+1

que=sorted(que, key=lambda x: x[1])
        
query=[]
for i in range(Q):
    l, r=list(map(int, input().split()))
    query.append((l,r,i))
query=sorted(query, key=lambda x: -x[1])

seg=BIT(N+1)
ans=[0]*Q



for i in range(len(que)):
    while query and query[-1][1]<que[i][1]:
        q=query.pop()
        l,r,j=q
        ans[j]=r-l+1-(seg.get(l-1,r))

    now=que[i]
    l, r=now  # index
    #A[l]+=1
    seg.add(l, 1)

    while query and query[-1][1]==r:
        q=query.pop()
        lq,rq,j=q
        
        ans[j]=rq-lq+1-(seg.get(lq-1,rq))
        #print(lq, rq, seg.query(lq,rq+1))
        #print(seg.get(lq,rq+1))

while query:
    q=query.pop()
    lq,rq,j=q     
    ans[j]=rq-lq+1-(seg.get(lq-1,rq))
    #print(lq, rq, seg.query(lq,rq+1))

for a in ans:
    print(a)


# Optimized solution
from collections import deque
N,Q=list(map(int, input().split()))

#重複分を引く

class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
        
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    # I: idx(base: 1), x: value
    def add(self, i, x):
        # assert i > 0
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
            
    # i<=x<j
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)


C=list(map(int, input().split()))
state=[-1]*N
que=[]
for i in range(N):
    c=C[i]
    if state[c-1]==-1:
        state[c-1]=i+1
    else:
        que.append((state[c-1],i+1))
        state[c-1]=i+1

que=sorted(que, key=lambda x: x[1])
        
query=[]
for i in range(Q):
    l, r=list(map(int, input().split()))
    query.append((l,r,i))
query=sorted(query, key=lambda x: -x[1])

seg=BIT(N+1)
ans=[0]*Q



for i in range(len(que)):
    while query and query[-1][1]<que[i][1]:
        l,r,j=query.pop()
        ans[j]=r-l+1-(seg.get(l-1,r))

    now=que[i]
    l, r=now  # index
    #A[l]+=1
    seg.add(l, 1)

    while query and query[-1][1]==r:
        lq,rq,j=query.pop()
        
        ans[j]=rq-lq+1-(seg.get(lq-1,rq))
        #print(lq, rq, seg.query(lq,rq+1))
        #print(seg.get(lq,rq+1))

while query:
    lq,rq,j=query.pop()   
    ans[j]=rq-lq+1-(seg.get(lq-1,rq))
    #print(lq, rq, seg.query(lq,rq+1))

for a in ans:
    print(a)