#include <bits/stdc++.h>
#define MOD 998244353
using namespace std;
const long long mod = 1000000007;
const int ll = 1005;
int main()
{
int n,m;
cin >> n >> m;
int add[ll],plus = 0;
int input[n];
for (int i = 0; i < n; i++) cin >> input[i];
for (int i = 0; i < n; i++)
{
for (int j = i; j <= i + 2; j++) plus += input[j];
add[i] = plus;
}
sort(add,add + ll);
int s = 0;
while (add[s] != 0) s++;
cout << add[s] << endl;
return 0;
}