private static int getMaximumNumberOfApples(final int[][] apples) {

        /** Set the "max" array. **/
        int[][] max = new int[N][M];

        /** For each Row... **/
        for (int i = 0; i < N; i++) {
            /** For each Column... **/
            for (int j = 0; j < M; j++) {
                if (i == 0 && j == 0) {
                    max[i][j] = 0;
                } else if (i == 0) {
                    max[i][j] += max[i][j - 1];
                } else if (j == 0) {
                    max[i][j] += max[i - 1][j];
                } else {
                    max[i][j] = Math.max(max[i - 1][j], max[i][j - 1]);
                }
                max[i][j] += apples[i][j];
            }
        }

        return max[N - 1][M - 1];
    }