Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, M := sc.nextInt(), sc.nextInt()
	m := sc.nextIntSlice(M)
	m = append(m, N)
	Q := sc.nextInt()
	l := sc.nextIntSlice(Q)
	base := m[0] - 1
	sums := make([]int, N+1)
	for i := 1; i <= M; i++ {
		var diff int
		if i != M {
			diff = m[i] - m[i-1] - 1
		} else {
			diff = m[i] - m[i-1]
		}
		for j := 0; j < diff; j++ {
			sums[j+1] += diff - j
		}
	}
	for _, allow := range l {
		ok := N + 1
		ng := 0
		for abs(ok-ng) > 1 {
			mid := (ok + ng) / 2
			if base+sums[mid] <= allow {
				ok = mid
			} else {
				ng = mid
			}
		}
		if ok == N+1 {
			fmt.Fprintln(wtr, -1)
		} else {
			fmt.Fprintln(wtr, ok)
		}
	}

	wtr.Flush()
}

C++: #include <bits/stdc++.h>
using namespace std;

long long n, m, q;
long long s[100005] = {0};
long long l[100005] = {0};
long long ans[100005] = {0};
long long cnt[100005] = {0};
vector<long long> dis;

void solve();

int main() {
  cin >> n >> m;
  for(long long i = 0; i < m; ++i) cin >> s[i];
  cin >> q;
  for(long long i = 0; i < q; ++i) cin >> l[i];
  solve();
  for(long long i = 0; i < q; ++i) {
    int nowans =
        lower_bound(ans + 1, ans + n + 1, l[i] - s[0] + 1,
                    greater<long long>()) -
        ans;
    if(ans[nowans] + s[0] - 1 > l[i]) nowans = -1;
    cout << nowans << endl;
  }
  return 0;
}

void solve() {
  for(int i = 1; i < m; ++i) {
    dis.push_back(s[i] - s[i - 1] - 1);
    ans[1] += dis[i - 1];
  }
  dis.push_back(n - s[m - 1]);
  ans[1] += n - s[m - 1];
  sort(dis.begin(), dis.end());
  for(int i = 1; i <= n; ++i) {
    auto it = lower_bound(dis.begin(), dis.end(), i - 1);
    cnt[i] = dis.end() - it;
  }
  for(int i = 2; i <= n; ++i) ans[i] = ans[i - 1] - cnt[i];
}