const log = console.log;

const parseLines = (s: string) => s.trim().split("\n");
const parseSpaceSeparated = (line: string) => line.trim().split(" ");

const parseDecimalInt = (s: string) => parseInt(s);

const parseSpaceSeparatedDecimalInt = (line: string) =>
  parseSpaceSeparated(line).map(parseDecimalInt);

const ascendingSorter = (a: number, b: number) => a - b;

const getMaxSum = (array: number[], limit: number) => {
  let sum = 0;
  let count = 0;

  for (const currentNum of array) {
    const nextSum = sum + currentNum;
    if (nextSum > limit) break;
    sum = nextSum;
    count += 1;
  }

  return { sum, count };
};

// ----

function Main(input: string): void {
  const [head, body] = parseLines(input);
  const [n, x] = parseSpaceSeparatedDecimalInt(head);
  const a = parseSpaceSeparatedDecimalInt(body);

  a.sort(ascendingSorter);

  log(getMaxSum(a, x).count);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));