#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int a[100005];
int l[1000], r[1000];
vector<int> v[100000];
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++) {
    int s, t;
    scanf("%d%d", &s, &t);
    l[i] = s, r[i] = t;
  }
  int ans = -100000000, anss = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int mi = a[i], ma = a[j];
      for (int k = 1; k <= m; k++) {
        if (l[k] <= i && i <= r[k] && (l[k] > j || r[k] < j))
          mi--, v[(i - 1) * 300 + j].push_back(k);
      }
      if (ans < ma - mi) {
        ans = ma - mi;
        anss = (i - 1) * 300 + j;
      }
    }
  }
  printf("%d\n", ans);
  printf("%d\n", v[anss].size());
  for (int i = 0; i < v[anss].size(); i++) printf("%d ", v[anss][i]);
  printf("\n");
  return 0;
}
