#include int sort(int n, int str[]); int main() { int l, n; scanf("%d%d", &l, &n); int str[10000]; int total = 0; int count = 0; for (int i = 0; i <= n - 1; i++) { scanf("%d", &(str[i])); } sort(n, str); for (int k = 0; k <= n - 1; k++) { if (total + str[k] <= l){ total += str[k]; count++; } } printf("%d", count); return 0; } int sort(int n, int str[]) { for (int i = 0; i < n - 2;i++) { for (int j = i + 1; j <= n - 1; j++) { int a; if (str[i] > str[j]) { a = str[i]; str[i] = str[j]; str[j] = a; } } } return 0; }