package no037; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int n = sc.nextInt(); int[] c = new int[n]; int[] v = new int[n]; int[][] v2 = new int[n][10]; for(int i=0;i> (j-1)); } } // System.out.println(Arrays.deepToString(v2)); int[][] dp = new int[n+1][t+1]; for(int i=1;i<=n;i++) { for(int j=1;j<=t;j++) { dp[i][j] = dp[i-1][j]; for(int k=1;k<10;k++) { int j2 = j - c[i-1] * k; if (j2 < 0) { break; } dp[i][j] = Math.max(dp[i][j], dp[i-1][j2] + v2[i-1][k]); } } } // System.out.println(Arrays.deepToString(dp)); int ans = 0; for(int i=1;i<=n;i++) { for(int j=1;j<=t;j++) { ans = Math.max(ans, dp[i][j]); } } System.out.println(ans); } }