using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bug
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int n = int.Parse(str[0]);
            int k = int.Parse(str[1]);
            str = Console.ReadLine().Split();
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(str[i]);
            }
            if (k == 0) Console.WriteLine(a.Sum());
            else if(k==1)
            {
                int i = 0;
                int j = 0;
                int l = 0;
                while(true)
                {
                    if (i == n) break;
                    for (int m = i; m < j+1; m++)
                    {
                        if (m == j)
                        {
                            l += a[j];
                            break;
                        }
                        l += a[m];
                    }
                    if (j == n - 1)
                    {
                        i++;
                        j = i;
                    }
                    else j++;
                }
                Console.WriteLine(l);
            }
        }
    }
}