#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const int MAXN = 500000 + 5;
const int MAXM = 600000 + 5;
int a[MAXN];
int l[MAXM], r[MAXM];
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  int ans = 0, ansq = 0, mini = 1, maxi = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] < a[mini]) {
      mini = i;
    }
    if (a[i] > a[maxi]) {
      maxi = i;
    }
  }
  ans = a[maxi] - a[mini];
  for (int j = 1; j <= m; j++) {
    cin >> l[j] >> r[j];
  }
  for (int p = 1; p <= n; p++) {
    for (int q = 1; q <= n; q++) {
      int _mini = p, _maxi = q;
      int _ans = a[_maxi] - a[_mini];
      int _ansq = 0;
      for (int j = 1; j <= m; j++) {
        if (l[j] <= _mini && r[j] >= _mini) {
          if (l[j] > _maxi || r[j] < _maxi) {
            _ans++;
            _ansq++;
          }
        }
      }
      if (_ans > ans) {
        ans = _ans;
        ansq = _ansq;
        mini = _mini;
        maxi = _maxi;
      }
    }
  }
  cout << ans << endl;
  cout << ansq << endl;
  for (int j = 1; j <= m; j++) {
    if (l[j] <= mini && r[j] >= mini) {
      if (l[j] > maxi || r[j] < maxi) {
        cout << j << " ";
      }
    }
  }
  return 0;
}
