#include <iostream>
#include <vector>

using namespace std;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n ,k, a;
    cin >> n >> k;
    vector<int> nums;
    for(int i = 0; i < n; ++i)
    {
        cin >> a;
        nums.push_back(a);
    }
    if(k == 2)
    {
        int w = max(nums[0], nums[n-1]);
        int e = min(nums[0], nums[n-1]);
        cout << w-e;
    }
    else{
        int sum = 0;
        for(int i = 0; i < n; i++)
            sum += nums[i];

        cout << sum/n;
    }
    return 0;
}