#include<bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
int main()
{
int n, m;
cin >> n >> m;
int a[N];
for (int i = 0; i < n; i++) cin >> a[i];
int cnt_min = 360;
for (int i = 0; i < n - 2; i++)
{
if ((a[i] + a[i + 1] + a[i + 2]) < cnt_min) cnt_min = a[i] + a[i + 1] + a[i + 2];
}
cout << cnt_min;
return 0;
}