#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, num[310], num1[310];
  int seg[310][2], ans = 0, cnt, reccnt, rec;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
  for (int i = 1; i <= m; i++) scanf("%d%d", &seg[i][0], &seg[i][1]);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) num1[j] = num[j];
    cnt = 0;
    for (int j = 1; j <= m; j++) {
      if (seg[j][0] > i) continue;
      if (seg[j][1] < i) continue;
      cnt++;
      for (int k = seg[j][0]; k <= seg[j][1]; k++) num1[k]--;
    }
    int tmp = num1[1];
    for (int j = 2; j <= n; j++)
      if (num1[j] > tmp) tmp = num1[j];
    if (tmp - num1[i] > ans) {
      ans = tmp - num1[i];
      reccnt = cnt;
      rec = i;
    }
  }
  printf("%d\n%d\n", ans, reccnt);
  for (int i = 1; i <= m; i++) {
    if (seg[i][0] > rec) continue;
    if (seg[i][1] < rec) continue;
    printf("%d ", i);
  }
}
