#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 5;

int m, n;
int a[N], L[N], R[N];
int maxf = 0;
int tlx, tly, brx, bry;

void solve(){
	stack<int> s;
	for (int i = 1; i <= n; i++){
    	while (!s.empty() && a[i] <= a[s.top()]) s.pop();
    	
	    if (s.empty()) L[i] = 1;
	    else L[i] = s.top() + 1;
	    s.push(i);
	}
  	while (s.size()) s.pop();
  	
  	for (int i = n; i >= 1; i--){
    	while (!s.empty() && a[i] <= a[s.top()]) s.pop();
    	
	    if (s.empty()) R[i] = n;
	    else R[i] = s.top() - 1;
	    s.push(i);
	}
  	while (s.size()) s.pop();
	
}
signed main(){
	cin.tie(0)->sync_with_stdio(0);
	freopen("maxrect.inp", "r", stdin);
  	freopen("maxrect.out", "w", stdout);
  	
  	cin >> m >> n;
  	for (int i = 1; i <= n; i++){
  		cin >> a[i];
  	}
	solve();
  	for (int i = 1; i <= n; i++){
  		//cout << i << " " << L[i] << " " << R[i] << "\n";
  		int tmp = a[i]*(R[i] - L[i] + 1);
    	if (tmp > maxf){
	     	maxf = tmp;
	      	tlx = 1;
	      	tly = L[i];
	      	brx = a[i];
	      	bry = R[i];
	    }
  	}
	for (int i = 1; i <= n; i++){
		a[i] = m - a[i];
	}
	solve();
  	for (int i = 1; i <= n; i++){
    	int tmp = a[i]*(R[i] - L[i] + 1);
    	if (tmp > maxf){
	     	maxf = tmp;
		    tlx = m - a[i] + 1;
		    tly = L[i];
		    brx = m;
		    bry = R[i];	
	    }
  	}
	cout << maxf << "\n";
	cout << tlx << " " << tly << "\n";
	cout << brx << " " << bry << "\n";
}