#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, max, min = 0, l1, r1, k;
  cin >> n >> m;
  int a[n], b[n], l[m], r[m];
  vector<int> o, p;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  for (i = 0; i < m; i++) cin >> l[i] >> r[i];
  for (k = 0; k < n; k++) {
    for (i = 0; i < m; i++) {
      if (((l[i] - 1) <= k && (r[i] - 1) >= k)) {
        for (j = l[i] - 1; j < r[i]; j++) a[j]--;
      }
    }
    max = a[0] - a[k];
    for (i = 0; i < n; i++) {
      if (max <= (a[i] - a[k])) max = (a[i] - a[k]);
    }
    o.push_back(max);
    for (i = 0; i < n; i++) a[i] = b[i];
  }
  max = -999999;
  r1 = o.size();
  for (i = 0; i < r1; i++) {
    if (max < o[i]) {
      max = o[i];
      l1 = i;
    }
  }
  min = 0;
  for (i = 0; i < m; i++) {
    if (((l[i] - 1) <= l1 && (r[i] - 1) >= l1)) {
      min++;
      p.push_back(i + 1);
    }
  }
  cout << o[l1] << endl;
  cout << min << endl;
  for (i = 0; i < min; i++) cout << p[i] << " ";
  return 0;
}
