import java.io.FileInputStream;
import java.util.InputMismatchException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.FileOutputStream;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class dibbles_iz {
	public static void main(String[] args) {
		InputStream inputStream;
		try {
			inputStream = new FileInputStream("dibbles.in");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		OutputStream outputStream;
		try {
			outputStream = new FileOutputStream("dibbles.out");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		dibbles solver = new dibbles();
		solver.solve(1, in, out);
		out.close();
	}
}

class dibbles {
    int n, k;
    int a[];

    long[] rec(int l, int r) {
        int min = Integer.MAX_VALUE;
        for (int i = l; i <= r; i++) {
            min = Math.min(min, a[i]);
        }

        long res[] = new long[r - l + 2];
        for (int i = 1; i <= r - l + 1; i++) {
            res[i] = Long.MAX_VALUE;
        }
        int countZero = 0;
        for (int i = l; i <= r; i++) {
            a[i] -= min;
            if (a[i] == 0) {
                countZero++;
            }
        }
        res[countZero] = min;
        int cur = countZero;
        for (int i = l; i <= r; i++) {
            if (a[i] == 0) continue;
            int j = i;
            while (j + 1 <= r && a[j + 1] != 0) {
                j++;
            }
            long ch[] = rec(i, j);
            for (int i1 = cur; i1 >= countZero; i1--) {
                for (int i2 = 0; i2 < ch.length; i2++) {
                    if (res[i1] != Long.MAX_VALUE && ch[i2] != Long.MAX_VALUE) {
                        res[i1 + i2] = Math.min(res[i1 + i2], res[i1] + ch[i2]);
                    }
                }
            }
            cur += j - i + 1;
            i = j;
        }
		return res;
    }

    public void solve(int testNumber, Scanner in, PrintWriter out) {
        n = in.nextInt();
        k = in.nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        long[] dp = rec(0, n - 1);
        int ans = 0;
        for (int i = 0; i <= n; i++) {
            if (dp[i] <= k) {
                ans = i;
            }
        }
        out.println(ans);
    }
}

class Scanner {
    BufferedReader in;
    StringTokenizer tok;

    public Scanner(InputStream in) {
        this.in = new BufferedReader(new InputStreamReader(in));
        tok = new StringTokenizer("");
    }

    private String tryReadNextLine() {
        try {
            return in.readLine();
        } catch (Exception e) {
            throw new InputMismatchException();
        }
    }

    public String nextToken() {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(next());
        }
        return tok.nextToken();
    }

    public String next() {
        String newLine = tryReadNextLine();
        if (newLine == null)
            throw new InputMismatchException();
        return newLine;
    }

    public int nextInt() {
        return Integer.parseInt(nextToken());
    }

}


