public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		while ((line = in.readLine()) != null && line.length() != 0) {
			int[] nq = readInts(line), ab;
			SegTree s = new SegTree(0, nq[0]+1);
			for (int i = 0; i < nq[0]; i++) 	
				s.set(i+1, Integer.parseInt(in.readLine()));
			for (int i = 0; i < nq[1]; i++) {
				ab = readInts(in.readLine());
				out.append((s.getMax(ab[0], ab[1])-s.getMin(ab[0], ab[1]))+"\n");
			}
		}
		System.out.print(out);
	}