#include <bits/stdc++.h>
using namespace std;
int v[301], a[301], b[301];
int n, m, res = 0;
int maxS, maxSegs[301], curSegs[301];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &v[i]);
  for (int i = 1; i <= m; i++) scanf("%d %d", &a[i], &b[i]);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      int mi = v[i], ma = v[j];
      int miId = i, maId = j;
      int c = 0;
      for (int k = 1; k <= m; k++) {
        if ((a[k] <= miId && miId <= b[k]) && (a[k] > maId || maId > b[k])) {
          c++;
          mi--;
          curSegs[c] = k;
        }
      }
      if (ma - mi > res) {
        res = ma - mi;
        maxS = c;
        for (int l = 1; l <= c; l++) maxSegs[l] = curSegs[l];
      }
    }
  }
  printf("%d\n%d\n", res, maxS);
  for (int i = 1; i <= maxS; i++) printf("%d ", maxSegs[i]);
  printf("\n");
  return 0;
}
