import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int w = sc.nextInt();
int[] a = new int[w];
for (int i = 0; i < w; i++) {
a[i] = sc.nextInt();
}
System.out.println(minMoneyBU(a, w));
}
public static int minMoneyBU(int a[], int w) {
int[][] strg = new int[w + 1][w + 1];
for (int row = 0; row <= w; row++) {
for (int col = 1; col <= w; col++) {
if (row == 0) {
strg[row][col] = Integer.MAX_VALUE;
} else {
if (row > col) {
strg[row][col] = strg[row - 1][col];
} else {
strg[row][col] = Math.min(strg[row - 1][col], strg[row][col - row] + a[row - 1]);
}
}
}
}
return strg[w][w] == Integer.MAX_VALUE ? -1 : strg[w][w];
}
}