#include <bits/stdc++.h>
using namespace std;
const int maxn = 400 + 100;
int a[maxn], b[maxn], sto[maxn];
struct node {
  int le;
  int ri;
} q[maxn];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &q[i].le, &q[i].ri);
  }
  int maxx = -0x3f3f3f3f, id = 0;
  for (int i = 1; i <= n; i++) {
    int t1 = -0x3f3f3f3f, t2 = 0x3f3f3f3f;
    for (int j = 1; j <= n; j++) {
      b[j] = a[j];
    }
    for (int j = 1; j <= m; j++) {
      if (i >= q[j].le && i <= q[j].ri) continue;
      for (int k = q[j].le; k <= q[j].ri; k++) {
        b[k] -= 1;
      }
    }
    for (int j = 1; j <= n; j++) {
      t1 = max(t1, b[j]);
      t2 = min(t2, b[j]);
    }
    if (t1 - t2 > maxx) {
      maxx = t1 - t2;
      id = i;
    }
  }
  printf("%d\n", maxx);
  int num = 0;
  for (int i = 1; i <= m; i++) {
    if (id >= q[i].le && id <= q[i].ri) continue;
    sto[++num] = i;
  }
  printf("%d\n", num);
  for (int i = 1; i <= num; i++) {
    if (i == 1)
      printf("%d", sto[i]);
    else
      printf(" %d", sto[i]);
  }
  printf("\n");
  return 0;
}
