import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int q = sc.nextInt(); int[] points = new int[n]; TreeMap counts = new TreeMap<>(); for (int i = 0; i < n; i++) { points[i] = sc.nextInt(); counts.put(points[i], counts.getOrDefault(points[i], 0) + 1); } int current = 0; for (int x : counts.keySet()) { current += counts.get(x); counts.put(x, current); } counts.put(0, 0); int[] lefts = new int[n]; int[] rights = new int[n]; for (int i = 0; i < n; i++) { lefts[i] = counts.lowerEntry(points[i]).getValue(); rights[i] = counts.get(points[i]); } StringBuilder sb = new StringBuilder(); while (q-- > 0) { int base = sc.nextInt() - 1; int target = sc.nextInt() - 1; sb.append(Math.max(0, lefts[base] - rights[target])).append("\n"); } System.out.print(sb); } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }